利用vb操作word的基本方法

利用VB操作WORD的基本方法

通过查阅资料,自我实践,经实验通过。

Dim MyWord As Word.Application
Dim MyWordBook As Word.Document
Set MyWord = New Word.Application
Set MyWordBook = MyWord.Documents.Add(ModelPath & "test.dot") '打开test.dot用户自定义的WORD模版
'MyWord = CreateObject("Word.Application")
' MyWord.Visible = False
' MyWord.Documents.Open ("test.doc")
' MyWord.ActiveDocument.Bookmarks.Item("MM").Select
' MyWord.Selection.Text = "从资料库取出的相应资料"
' MyWord.ActiveDocument.SaveAs ("test1.doc")
MyWordBook.Activate
With MyWordBook
'    .Paragraphs(.Paragraphs.Count).Range.Font.Size = 30 '设置文字字体大小(其它设置类推) 如果去除.Paragraphs(.Paragraphs.Count)则表示所有行
'    .Paragraphs(.Paragraphs.Count).Alignment = wdAlignParagraphCenter '设置文字居中等
'    .Content.InsertAfter "hello" & vbCrLf     '向WORD写入一行文字并回车
'    .Content.InsertAfter "hello"
'    .Paragraphs(.Paragraphs.Count).Range.Font.Size = 10
'    .Content.InsertAfter "hello"
    .Bookmarks("mm").Range.InsertAfter "name"    '在WORD指定位置(标签)写入文本,指定位置指WORD标签
    .Tables(1).Cell(2, 1).Range.InsertAfter "nameFDSAFDSAFDSA" '在WORD第一个表格的第2行第1列插入文本
    .Tables(1).Cell(2, 2).Range.InsertAfter "MM"
    .Range(Start:=.Paragraphs(2).Range.Start + 3, End:=.Paragraphs(2).Range.Start + 8).Font.Size = 30 '给选定的文本(第二段开始位置加3至8的字体)设置字体,其它的累推
    .Tables(1).Cell(2, 1).Range.Font.Size = 20 '给选定的单元格设置字体,其它的累推
End With
MyWord.Visible = True
Set MyWord = Nothing
Set MyWordBook = Nothing

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值