如何在不从剪贴板拖动的情况下进行粘贴?
(代码示例摘自谷歌搜索和录音。(
VBA代码从表单中填充文档的某个节。在加载下一个表单之前,它会将该节的内容复制到对象中。
代码继续进一步填充文档。当完成时,用户可以选择";"下一页";控件,该控件生成新页面
我想将保存的对象粘贴到新页面的开头。
我的代码一直粘贴到粘贴点。
Sub waiverCopy()
Dim objRange As Range
'Capture first section of document (waiver with names etc. populated)
Set objRange = ActiveDocument.Range(Start:=0, End:=ActiveDocument.Sections(1).Range.End)
Debug.Print objRange 'DOES PRINT contents in immediate window
' continue populating rest of current page '
Selection.EndKey Unit:=wdStory 'position to end of document (i.e. current page)
Selection.InsertBreak Type:=wdPageBreak 'start new page
' Nothing of the myriad of things I've tried will paste the contents of objRange on new page
End Sub
如果不想使用剪贴板,只需在创建分页符后将范围对象插入当前Selection
位置(Selection.FormattedText = objRange
(即可。
Sub Copy()
Dim objRange As Range
'Capture first section of document (waiver with names etc. populated)
Set objRange = ActiveDocument.Range(Start:=0, End:=ActiveDocument.Sections(1).Range.End - 1)
' continue populating rest of current page '
Selection.EndKey Unit:=wdStory 'position to end of document (i.e. current page)
Selection.InsertBreak Type:=wdPageBreak 'start new page
Selection.FormattedText = objRange
' Don´t forget to clean memory
Set objRange = Nothing
End Sub
请不要忘记使用Set objRange = Nothing
清理内存。