如何将WORD模板中的字符串替换 如何将WORD模板中的字符串替换,如将(name) 换成姓名张三? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 打开Word,在菜单的"工具"->"宏"->"录制新宏",然后开始对Word操作(比如 将(name) 换成姓名张三 等),操作完了停止录制宏,在"宏"->"Visual Basic编辑器"->"模块"里的模块就有你录制的过程的代码,把需要的代码稍微修改就可以直接应用到vb里 引用Mircrosoft.Word11.Object Library(office 2003),低版本的自己查找 Dim wordApp As New Word.Application With wordApp .Visible = True .Activate .Documents.Open ("c:\1.doc") .Selection.Find.ClearFormatting .Selection.Find.Replacement.ClearFormatting With .Selection.Find .Text = "name" .Replacement.Text = "张三" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With .Selection.Find.Execute Replace:=wdReplaceAll End With to jobs002一个变量替换已解决,但替换多个时却有问题,如(name) 换成姓名张三,(sex)换成性别男,即无法换成多个 那就用faysky2() 的方法,自己录制一个宏,宏的Selection是word.Application的子对象 Dim wordApp As New Word.Application With wordApp .Visible = True .Activate .Documents.Open ("c:\1.doc") .Selection.Find.ClearFormatting .Selection.Find.Replacement.ClearFormatting With .Selection.Find .Text = "name" .Replacement.Text = "张三" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With .Selection.Find.Execute Replace:=wdReplaceAll With .Selection.Find .Text = "sex" .Replacement.Text = "男" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With .Selection.Find.Execute Replace:=wdReplaceAll End With jobs002(赏花赏月赏春光) 的方法确实不错 wordApp.Selection.Find.ClearFormattingWith wordApp.Selection.Find.Text = "(jsyname)".Replacement.Text = jsyname.Execute Replace:=wdReplaceAll.Text = "(yzbm)".Replacement.Text = yzbm.Execute Replace:=wdReplaceAll 如果queryunload中有判断是否退出的代码,如果用代码关闭窗体而不出现退出判断提示呢? 大家一起研究下VB下创建SYSTEM进程 webbrowser中触发select中on_change事件 Inet1_StateChanged(ByVal State As Integer)事件遇到的问题 急啊,没作个串行通讯的实验,救命啊 请教大家,谢谢! 那里有VB的反编译软件下载? 用VB写控件的疑问与请教 报表问题DataReport 请教一个问题?Thank You! :> 数据更新!在线等! 數據集一問,在線等
Dim wordApp As New Word.Application
With wordApp
.Visible = True
.Activate
.Documents.Open ("c:\1.doc")
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find
.Text = "name"
.Replacement.Text = "张三"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Selection.Find.Execute Replace:=wdReplaceAll
End With
一个变量替换已解决,但替换多个时却有问题,如(name) 换成姓名张三,(sex)换成性别男,即无法换成多个
With wordApp
.Visible = True
.Activate
.Documents.Open ("c:\1.doc")
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find
.Text = "name"
.Replacement.Text = "张三"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Selection.Find.Execute Replace:=wdReplaceAll
With .Selection.Find
.Text = "sex"
.Replacement.Text = "男"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Selection.Find.Execute Replace:=wdReplaceAll
End With
With wordApp.Selection.Find
.Text = "(jsyname)"
.Replacement.Text = jsyname
.Execute Replace:=wdReplaceAll
.Text = "(yzbm)"
.Replacement.Text = yzbm
.Execute Replace:=wdReplaceAll