vb +word


 

  Dim wdApp As New Word.Application       'word   应用对象
  Dim wdDoc As Document     '文档对象
  Dim wdTable As Table     '表格
  Set wdDoc = wdApp.Documents.Add
  Set wdTable = wdDoc.Tables(1)
   wdApp.Visible = True
  

 //插入图片 

  Dim shapeCode As Word.Shape
  Set shapeCode = wdDoc.Shapes.AddPicture("d:\VB OFFICE\test.jpg", True, True) 

wordApp.Find.MatchAllWordForms = False

  ActiveDocument.Paragraphs(1).Range.Select
  Selection.Cut
  ActiveDocument.Range(100, 100).Select
  Selection.Paste 

//插入点移至文档末尾

Selection.ShapeRange.Line.Visible = msoFalse

//当然了,若是将Set myrange = ActiveDocument.Range改成Set myrange = ActiveDocument.Range
(ActiveDocument.Paragraphs(1).Range.Start,ActiveDocument.Paragraphs(4).Range.End)将会把插入点移至第四段结尾处,若把wdCollapseEnd改成wdCollapseStart则相应的移至开头。

//打开已有文档,复制其中的内容到一个新建文档

AA:

//运转到这里有个问题,就是图片总是在第一段首,下面我要研究一下怎么把他放到光标的位置

就是word中自带的绘图功能:就是绘图工具栏上的那些功能。

就会把图片放在你所选定的位置了,若是像上面写成Set shapeCode = wdDoc.Shapes.AddPicture("d:\VB OFFICE\test.jpg", True, True) ,就会把图片放在文档开头,因为是wdDoc.嘛,胡涂了我,这么简单的问题想这么久!不过在这过程中发现了一篇很有用的文章,收拾整顿出来存下 HOHO 多学无害

//修改表格添加行

可以用查找替换的,或者试试这个

======================================================================================

VB调用WORD中的图片问题(转)

 

本示例在名为“Changes.doc”的文档末尾插入文本。“For Each...Next”语句用来判断此文档是否已打开。

若何在word文档中以shape类型将图片加入到光标所在位置??且使这个图片不可删除??并将图片的层设置在文字之下,其他图片之上??即,文字可透过图片看到,而其他图片又不会覆盖掉这个图片??

第一种:shape (内嵌式图片)

//挖咔咔,颠末我不懈的尽力发现:写成Selection.InlineShapes.AddPicture ("d:\VB OFFICE\test.jpg")

第二种:inlineshape(嵌入式图片)

就是通过“插入”->“图片”->“来自文件...”

----------------------------------------------------------------

End If

而inlineshape(嵌入式图片)是有具体位置的,也就是说inlineshape是可以插入到文字中间的,是有插入点位置的。

Selection.InsertBreak Type:=wdSectionBreakContinuous

不过,inlineshape在插入这后,只有编号,位置,出着名字,

但是在有一个解决的方法,就是在插入图片的时候,在inlineshape图片对象的一个“可选文字”里写上图片的名字,

到时候再用循环去判断

1 XXXX

Selection.ShapeRange.RelativeVerticalPosition = _

if worddoc.inlineshapes(i).AlternativeText = "你的图片的名字" then 

.....

end if 

next i

If ActiveDocument.Shapes.Count + ActiveDocument.InlineShapes.Count > 0 Then

Selection.ShapeRange.WrapFormat.DistanceTop = CentimetersToPoints(0)

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

 

======================================================================================

Selection.ShapeRange.WrapFormat.DistanceBottom = CentimetersToPoints(0)

8月3日
这些VBA代码会有用

Wrd.ActiveDocument.Close

AA:

xlSheet.UsedRange.Rows.Count

'oW.Visible = True

QQ:

若何打开一个word的模板!

  Set myrange = ActiveDocument.Range
  myrange.Select
  Selection.Collapse(wdCollapseEnd)

End Sub

AA:

On Error Resume Next '忽略错误

Set Wrd = GetObject(, "Word.Application") '查找一个正在运转的Word拷贝

If Err.Number <> 0 Then '若是 Word 出有运转则

Set Wrd = CreateObject("Word.Application") '运转它

End If

Err.Clear '清除产生错误的 Err 对象

On Error GoTo 0 '保留普通错误进程

Dim dot As String

QQ:有出有法子获得一个excle表的行的总数和列的总数??

Wrd.Visible =true

dot = "C:\temp.dot"

doc = "c:\temp.doc"

Documents.Open FileName:=dot, _

ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False, _

PasswordDocument:="", PasswordTemplate:="", Revert:=False, _

WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _

0

wordApp.Find.MatchCase = False

Wrd.Documents.Add Template:=dot, NewTemplate:=False

'成绩系列操作

ActiveDocument.SaveAs FileName:=doc, FileFormat:=wdFormatDocument, _

LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _

:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _

wordApp.Find.Execute

AA:

'打印出来

ActiveDocument.PrintOut FileName:=doc, Range:=wdPrintAllDocument, Item:= _

strFileName = App.Path & "\temp.dot"

ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _

False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _

PrintZoomPaperHeight:=0

ActiveDocument.Sections(2).ProtectedForForms = True

WORD中打字

myShape.WrapFormat.Type = wdWrapNone

若何让Word的保存命令调用我自己编写的保存方法?

在doc文档被修改以后,在退出的时候当提示用户文档已经修改,问是否保存

和直接点击保存按钮的时候,可否让Word去调用我自己编写的SaveDoc方法,

若何实现?

创建名为“FileSave”的宏,把你的代码写入在这个宏中。当点击“保存”按钮或退出程序要求“保存”时,城市直接执行你的“FileSave”宏,而不再执行Word的内置命令。

LinkToFile:=False, SaveWithDocument:=True)

Word里的图片包括两种(据我所知),楼上的漏掉了InlineShapes

 

Else

MsgBox "Document doesn't contain a shape"

Dim wrdapp As Word.Application

QQ:怎样在程序中把图片写入到word中。

AA:

功能是:在指定位置插入图片并设置图片的花样(包括设置为衬托于文字下    方)

Sub 设置图片花样()

Selection.InlineShapes.AddPicture FileName:="D:\Mypicture\800x600.jpg", _

Next x

Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

Selection.InlineShapes(1).ConvertToShape.Select

QQ:若何访问表格单元格内容

Selection.ShapeRange.Fill.Transparency = 0#

Selection.ShapeRange.Line.Weight = 0.75

Selection.ShapeRange.Line.DashStyle = msoLineSolid

VB代码word,excel

Selection.ShapeRange.Line.Transparency = 0#

最近做一个word的模板程序,打开word是Set NewDoc = MyWord.Documents.Add

Selection.ShapeRange.LockAspectRatio = msoTrue

Set MyInshape = Selection.InlineShapes.AddPicture(FileName:="D:\pic001.jpg", _

Selection.ShapeRange.Width = 481.6

Selection.ShapeRange.PictureFormat.Brightness = 0.5

dim s as string

Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic

wdRelativeHorizontalPositionColumn

Selection.ShapeRange.PictureFormat.CropRight = 0#

Selection.ShapeRange.PictureFormat.CropTop = 0#

Selection.ShapeRange.PictureFormat.CropBottom = 0#

1.1 YYYY

Selection.ShapeRange.PictureFormat.CropLeft = 0#

for i=1 to wordDoqq邮箱c.inlineshapes.count

Private Sub Command2_Click()

Selection.ShapeRange.Left = wdShapeCenter

Selection.ShapeRange.Top = wdShapeCenter

Selection.ShapeRange.LockAnchor = False

Selection.ShapeRange.WrapFormat.Side = wdWrapBoth

 

Selection.ShapeRange.Line.Style = msoLineSingle

Selection.ShapeRange.WrapFormat.DistanceLeft = CentimetersToPoints(0.32)

Selection.ShapeRange.WrapFormat.DistanceRight = CentimetersToPoints(0.32)

'将InlineShape对象转变成Shape对象

‘现实上真正有用的是下面的语句设置图片为衬托于文字下方

Selection.ShapeRange.ZOrder msoSendBehindText

这是一个新的doc,名字叫文档1(后面会累加,自动的),但是现在我希望直接新建打开一个我写好的模板程序,名字还是叫文档1。请问该当怎么写!

QQ:有出有方法,把一个word文件,按编号返回一段一段的段落文章。

比如

dim i as long

Selection.ShapeRange.RelativeHorizontalPosition = _

1.1.1 ZZZZ

QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ

1.1.2 SSSS

MsgBox "esit"

a = Selection.Words.Count

我现在可以打开文件和插入图片了,就是出有搜索单词、移动光标、插入指定大小的图片的功能,那位老大出来指点指点呀?

AA:

加载Microsoft Word 9.0 Object Library

Dim dcApp As Word.Application

Dim dcWd As Word.Document

Private Sub Form_Load()

Set dcApp = New Word.Application

Set dcWd = dcApp.Documents.Open("c:\rpt.doc")

For i = 1 To dcWd.Paragraphs.Count

Set myrange = ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count, ActiveDocument.Tables(1).Columns.Count).Range
   myrange.Select
   Selection.MoveRight
   Selection.InsertRows (5)

Next

Dim docWord As Word.Document

Set dcWd = Nothing

dcApp.Quit

Set dcApp = Nothing

End Sub

AA:

在word模版中指定了boolmark:a,

Set wrddoc = wrdapp.Documents.Open(strFileName)

Dim wrddoc As Word.Document

Dim strFileName As String

Debug.Print dcWd.Paragraphs(i).Range.Text

ActiveDocument.BuiltInDocumentProperties(wdPropertyLines)

s="要插入的字符"

wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _

Set wrdapp = CreateObject("Word.Application")

End If

i = wrddoc.Range.GoTo(wdGoToBookmark, , , "a")

后面该若何写,才能将s插入到bookmark后面?另外我上面的代码准确吗?谢谢

??????????????

QQ: VBA:在word文档中搜索单词“审稿人”,将光标移到它后面,插入图片?怎么实现!!!

谢谢

我的代码如下:

Option Explicit

Dim Doc As New Document

Dim Visi As Boolean

Dim wordApp As Word.Application

dcWd.Close

wdRelativeVerticalPositionPage

ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

Set docWord = Word.Documents.Open("D:\test.doc")

ActiveDocument.Shapes.AddPicture ("d:\shan.jpg")

WORD XP的VB扶助中有示例:

docWord.Close

wordApp.Application.Quit()

End Sub

AA:

wordApp.Find.ClearFormatting

AA:

wordApp.Find.Replacement.Text = ""

wordApp.Find.Forward = True

wordApp.Find.Wrap = wdFindContinue

wordApp.Find.Format = False

Wrd.ActiveDocument.Close

wordApp.Find.MatchWholeWord = False

wordApp.Find.MatchByte = True

wordApp.Find.CorrectHangulEndings = False

  //同一篇文档的粘贴复制

wordApp.Find.MatchSoundsLike = False

wordApp.Find.MatchWildcards = False

wordApp.Find.MatchFuzzy = False

SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _

QQ:请问若何将加载的菜单不是以悬浮的菜单形式出现?

AA:CommandBar的Position属

QQ: 在vb 中将word文件保存为纯文本

AA:

Private Sub Command1_Click()

Dim oW As Object, oD As Object, x As Object

Set oW = CreateObject("word.application")

Set oD = oW.documents.open("c:\aaa.doc")

xlSheet.UsedRange.Cols.Count

For Each x In oD.words

LinkToFile:=False, SaveWithDocument:=True

Text1 = Text1 & x

Open "c:\bbb.txt" For Output As #1

Print #1, Text1

Close #1

oW.quit

End Sub

能够返回 一个编号对应的一个标题和一段话。

MsgBox "共删除空白段落" & m & "个"

docWord.Save

QQ:请问怎么插入图片的

For Each aDocument In Documents

闭于inlineshape图片定位的问题,以前也有人问过,我的也试着解决过,

Set myRange = Documents("Changes.doc").Content

myRange.InsertAfter "the end."

shape(内嵌式图片)是出有具体的插入位置的,只有一个“锚链”的位置。

Next aDocument

QQ:在WORD的宏里若何编写查询页数和行数,

wordApp.Find.Text = "审稿人"

Set wordApp = New Word.Application

Selection.ShapeRange.PictureFormat.Contrast = 0.5

QQ:请问网页考到word后,那个向下的箭头是什么标记,若何自动替换掉?手工替换很麻烦阿!但又不晓得这是什么标记,无法下手阿。急用!!

AA:

手工换行符

Dim i As Variant

Sub blankdel()

Dim i As Integer

For i = ActiveDocument.Paragraphs.Count To 1 Step -1

ActiveDocument.Paragraphs(i).Range.Select

QQ:怎么在一个word文档的最后插入东西

If a = 1 Then

Selection.Delete

m = m + 1

End If

Next i

AA:

End Sub

按ALT+F11,把代码COPY进去运转一下就行了

QQ:请问怎么样用word对象中控制word的分页?

AA:

我刚刚试出来的:此VB6下的代码可以解你问题

Set pword = CreateObject("Word.Application")

pword.Documents.Add dotName, False

pword.WindowState = 2 'wdWindowStateMinimize '2

pword.Selection.InsertBreak wdPageBreak

QQ:我想控制用户只能修改Word文件的部份内容,所以需要设置部分区域为只读,不晓得该用什么方法,请大家赐教。

False

If InStr(LCase$(aDocument.Name), "changes.doc") Then

ActiveDocument.Sections(1).ProtectedForForms = False

Dim doc As String

ActiveDocument.Protect Password:="", NoReset:=False, Type:= _

wdAllowOnlyFormFields

    Set wddoc = wdapp.Documents.Open("D:\VB OFFICE\test.doc")
    ActiveDocument.Paragraphs(1).Range.Select
    Selection.Copy
    wddoc.Close
    
    Set wddoc = wdapp.Documents.Add
    ActiveDocument.Range(0, 0).Select
    Selection.Paste
    wdapp.Visible = True  

Dim myShape As Shape

Dim MyInshape As InlineShape

怎么样判断Word文档中有出有图片?

Selection.ShapeRange.Height = 361.4

'插入一个嵌入式图片对象

Selection.ShapeRange.WrapFormat.Type = 3

Set myShape = MyInshape.ConvertToShape

'使图片浮于文字上方

Selection.TypeText Text:="您好,先生"

Selection.ShapeRange.Fill.Visible = msoFalse

QQ:若何用vb实现在word的bookmark后插入字符

objWordDoc.Tables(3).Cell(1, 1).Range.Text


Selection.ShapeRange.WrapFormat.AllowOverlap = True


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值