我有一小部分VBA代码可以工作并将文件插入到单词内的特定书签中,但是我很难从插入的文件格式化文本,要么使用书签的格式要么使用指定插入时的格式。
工作代码
File_purchase_inv_def = HarvDir + "\v1live" + "\Purchase_Invoices.def"
Selection.Range.InsertFile FileName:=(File_purchase_inv_def)
oRng = ActiveDocument.Bookmarks("BK_Puchase_Invioces").Range
oRng.Select
Selection.Range.InsertFile FileName:=(File_purchase_inv_def)
我试图使用的格式是“Verdana”和字体大小“7”我尝试格式化书签的区域以及下面的代码。
不起作用Example1
File_purchase_inv_def = HarvDir + "\v1live" + "\Purchase_Invoices.def"
Selection.Range.InsertFile FileName:=(File_purchase_inv_def)
oRng = ActiveDocument.Bookmarks("BK_Puchase_Invioces").Range
oRng.Select
Selection.Range.InsertFile FileName:=(File_purchase_inv_def)
With .Styles(Normal).Font
.Name = "Verdana"
.Size = 7
End with
不工作示例2
File_purchase_inv_def = HarvDir + "\v1live" + "\Purchase_Invoices.def"
Selection.Range.InsertFile FileName:=(File_purchase_inv_def)
oRng = ActiveDocument.Bookmarks("BK_Puchase_Invioces").Range
oRng.Select
Selection.Range.InsertFile FileName:=(File_purchase_inv_def)
Selection.Font.Name = "Verdana"
Selection.Font.Size = 7
答案 0 :(得分:0)
这将使用书签的格式并替换书签所具有的任何文本:
Dim fPath
fPath = "C:\Users\TestUser\Desktop\test.txt"
ActiveDocument.Bookmarks("BK_Puchase_Invioces").Range.Text = _
CreateObject("scripting.filesystemobject").opentextfile(fPath).ReadAll()
答案 1 :(得分:0)