我的代码几乎工作…但我有一个问题,插入图像在一个文档的末尾。这个vbs脚本的目的是:
- 在文档的末尾插入图像
- 将此文档从doc转换为docx
bRecursive = False
PicPath = "C:totosignature.jpg"
sFolder = "C:toto"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oFolder = oFSO.GetFolder(sFolder)
ConvertFolder(oFolder)
oWord.Quit
Sub ConvertFolder(oFldr)
For Each oFile In oFldr.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "doc" Then
Set oDoc = oWord.Documents.Open(oFile.path)
Set r1 = ActiveDocument.GoTo(What:=wdGoToLast)
r1.InlineShapes(1).Select
Selection.InlineShapes.AddPicture FileName:=PicPath, LinkToFile:=False, SaveWithDocument:=True
oWord.ActiveDocument.SaveAs oFile.path & "x", 12
oDoc.Close
End If
Next
If bRecursive Then
For Each oSubfolder In oFldr.Subfolders
ConvertFolder oSubfolder
Next
End If
End Sub
谢谢你的帮助。
尝试:
Sub ConvertFolder(oFldr)
For Each oFile In oFldr.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "doc" Then
Set oDoc = oWord.Documents.Open(oFile.Path)
oDoc.Range.InsertAfter vbCr
oDoc.InlineShapes.AddPicture FileName:=PicPath, LinkToFile:=False, _
SaveWithDocument:=True, Range:=oDoc.Range.Characters.Last
oDoc.SaveAs oFile.Path & "x", 12
oDoc.Close
End If
Next
If bRecursive Then
For Each oSubfolder In oFldr.Subfolders
ConvertFolder oSubfolder
Next
End If
End Sub