怎么将word的宏 转成VB里直接使用 或者VB调用宏 循环修改一些变量并执行
word的宏代码如下Sub 替换()
'
' 替换 Macro
' 宏在 2016-04-14 由 Microsoft 录制
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "名称" //要替换的目标
.Replacement.Text = "9999999" //替换的内容
.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 Sub
VB其中一段代码如下
On Error Resume Next
If CommonDialog1.FileName = "" Then
CommonDialog1.DialogTitle = "文件保存"
CommonDialog1.Filter = "Microsoft Word(*.doc)|*.doc|所有文件(*.*)|*.*"
CommonDialog1.ShowSave
If Err.Number = 32755 Then Exit Sub
Else
panduan = MsgBox("是否保存为当前路径", vbYesNoCancel, "提示")
If panduan = vbNo Then
CommonDialog1.FileName = Left$(CommonDialog1.FileName, InStr(CommonDialog1.FileName, ".") - 1) & "封面.doc"
CommonDialog1.DialogTitle = "文件保存"
CommonDialog1.Filter = "Microsoft Word(*.doc)|*.doc|所有文件(*.*)|*.*"
CommonDialog1.ShowSave
If Err.Number = 32755 Then Exit Sub
ElseIf panduan = vbCancel Then
Exit Sub
End If
End If
Dim MyWord As Word.Application
Dim MyWordBook As Word.Document
Set MyWord = CreateObject("Word.Application")
Set MyWordBook = MyWord.Documents.Add(App.Path & "\数据" & "\封面.doc")
MyWord.Visible = True
MyWordBook.Save
MyWord.Quit
Set MyWord = Nothing
Set MyWordBook = Nothing
MsgBox "保存成功", vbOKOnly, "提示"
想要的效果就是像在word中全部替换那样的功能
谢谢 求助各位大神帮忙