Word VBA - 在新文档中复制粘贴 Image-header
Word VBA - CopyPaste Image-header in a new Document
我有一个函数可以将指定的 table 复制到新文档中,但我不知道如何导出 header,它是一个图像,并将其设置为 header 用于文档的页面。
table是根据combobox的实际值(ProjectsList.Value)选择的,指的是
书签和其中包含的table在新文档
中成功copy-pasted
对于每个粘贴的页面,我也想复制 header。
我将集成 header 部分的函数:
Sub CopyPaste()
Dim Source As Document
Dim Target As Document
Dim tbl As Table
Dim tr As Range
Dim hRange As Word.Range
Set Source = ActiveDocument
Set Target = Documents.Add
Target.SaveAs FileName:=ProjectsList.Value
For Each tbl In Source.Bookmarks(ProjectsList.Value).Range.Tables
Set tr = Target.Range
tr.Collapse wdCollapseEnd
tr.FormattedText = tbl.Range.FormattedText
tr.Collapse wdCollapseEnd
tr.Text = vbCrLf
Next
End Sub
例如:
Sub Replicate()
Application.ScreenUpdating = False
Dim Source As Document, Target As Document
Dim Tbl As Table, HdFt As HeaderFooter, Rng As Range
Set Source = ActiveDocument: Set Target = Documents.Add
With Target
For Each Tbl In Source.Bookmarks(ProjectsList.Value).Range.Tables
Set Rng = .Range.Characters.Last
Rng.FormattedText = Tbl.Range.FormattedText
Rng.InsertAfter vbCr
Next
For Each HdFt In Source.Sections.First.Headers
With HdFt
Set Rng = Target.Sections.First.Headers(.Index).Range
Rng.FormattedText = .Range.FormattedText
Rng.Characters.Last.Delete
End With
Next
.SaveAs FileName:=ProjectsList.Value
End With
Application.ScreenUpdating = True
End Sub
我有一个函数可以将指定的 table 复制到新文档中,但我不知道如何导出 header,它是一个图像,并将其设置为 header 用于文档的页面。
table是根据combobox的实际值(ProjectsList.Value)选择的,指的是 书签和其中包含的table在新文档
中成功copy-pasted对于每个粘贴的页面,我也想复制 header。
我将集成 header 部分的函数:
Sub CopyPaste()
Dim Source As Document
Dim Target As Document
Dim tbl As Table
Dim tr As Range
Dim hRange As Word.Range
Set Source = ActiveDocument
Set Target = Documents.Add
Target.SaveAs FileName:=ProjectsList.Value
For Each tbl In Source.Bookmarks(ProjectsList.Value).Range.Tables
Set tr = Target.Range
tr.Collapse wdCollapseEnd
tr.FormattedText = tbl.Range.FormattedText
tr.Collapse wdCollapseEnd
tr.Text = vbCrLf
Next
End Sub
例如:
Sub Replicate()
Application.ScreenUpdating = False
Dim Source As Document, Target As Document
Dim Tbl As Table, HdFt As HeaderFooter, Rng As Range
Set Source = ActiveDocument: Set Target = Documents.Add
With Target
For Each Tbl In Source.Bookmarks(ProjectsList.Value).Range.Tables
Set Rng = .Range.Characters.Last
Rng.FormattedText = Tbl.Range.FormattedText
Rng.InsertAfter vbCr
Next
For Each HdFt In Source.Sections.First.Headers
With HdFt
Set Rng = Target.Sections.First.Headers(.Index).Range
Rng.FormattedText = .Range.FormattedText
Rng.Characters.Last.Delete
End With
Next
.SaveAs FileName:=ProjectsList.Value
End With
Application.ScreenUpdating = True
End Sub