|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 替换(文字, 替换后)
- With ActiveDocument.Content.Find
- .ClearFormatting
- .Wrap = wdFindStop
- .text = 文字
- .Forward = True
- .Replacement.text = 替换后
- .Execute Replace:=wdReplaceAll
- End With
- End Sub
- Sub word模板根据Execl生成多个Word文档()
- Dim xlApp, MYPT, myfile, Data
-
- '设置EXCEL应用程序的引用
- Set xlApp = CreateObject("Excel.Application")
- '设置要打开的文档
-
- MYPT = ActiveDocument.path
- myfile = "求助.xlsx"
- xlApp.Workbooks.Open MYPT & "" & myfile
- xlApp.Visible = False
-
- Data = xlApp.Sheets(1).Range("A1").CurrentRegion
- xlApp.Quit
- Set xlApp = Nothing
-
- Dim doc0, tempDoc As Document
- Dim str As String, i As Long
- Set doc0 = ActiveDocument
- str = doc0.FullName
- str = Split(doc0.FullName, ".")(0) & "生成的文件." & Split(str, ".")(1)
- Set tempDoc = Documents.Add(Visible:=True)
- tempDoc.Range.FormattedText = doc0.Content
- For i = 2 To UBound(Data)
- Call 替换(Data(i, 1), Data(i, 2))
- Next i
- tempDoc.SaveAs2 FileName:=str
- ' tempDoc.Close
- MsgBox "已安模板生成了文件,文件夹位置:" & doc0.path
- End Sub
复制代码 |
|