如何从vb中向文档插入文字,并设置格式?

stuman 2006-09-26 07:43:11
Private Sub CommandButton1_Click()

Dim doc As Document
Set doc = ActiveDocument
Set myRange = doc.Range(Start:=0)
myRange.InsertAfter TextBox1.Text

ActiveDocument.Paragraphs(1).Alignment = wdAlignParagraphCenter
Set myRange = ActiveDocument.Paragraphs(1).Range
With myRange.Font
'.Bold = True
.Name = "方正小标宋简体"
.Size = 48
End With

End Sub
===================================
以上代码是利用vba将文本框里的文字插入当前文档中,请问如果在vb中应该怎么做?谢谢

...全文
421 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cangwu_lee 2006-11-09
  • 打赏
  • 举报
回复
路过

jam021 2006-11-09
  • 打赏
  • 举报
回复
o,错了
set oApp = createobject("Word.Application")
jam021 2006-11-08
  • 打赏
  • 举报
回复
在VB里new出word对象
set oApp =new Word.Application
然后在vba代码前,加上word对象名
Set doc = oApp.ActiveDocument
..........
oApp.ActiveDocument.Paragraphs(1).Alignment = wdAlignParagraphCenter
northwolves 2006-09-28
  • 打赏
  • 举报
回复
引用WORD APPLICATION后按1楼代码如法炮制即可。
Hassle 2006-09-28
  • 打赏
  • 举报
回复
引用Word.Application

dim oApp as Word.Application

set oApp =new Word.Application

oApp.ActiveDocument

...
stuman 2006-09-28
  • 打赏
  • 举报
回复
自己顶一下

2,506

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧