![編寫 Excel VBA 將文字從一個 Word 文件複製到另一個 Word 文件 - 不保留頁尾格式](https://rvso.com/image/1595521/%E7%B7%A8%E5%AF%AB%20Excel%20VBA%20%E5%B0%87%E6%96%87%E5%AD%97%E5%BE%9E%E4%B8%80%E5%80%8B%20Word%20%E6%96%87%E4%BB%B6%E8%A4%87%E8%A3%BD%E5%88%B0%E5%8F%A6%E4%B8%80%E5%80%8B%20Word%20%E6%96%87%E4%BB%B6%20-%20%E4%B8%8D%E4%BF%9D%E7%95%99%E9%A0%81%E5%B0%BE%E6%A0%BC%E5%BC%8F.png)
請幫我解決這個問題。我已成功將一個Word文件的內容複製到另一個Word文件。但是貼上內容後頁腳格式發生了變化。下面是我的程式碼。
Sub CopyFile_Blank()
Dim Word As New Word.Application
Dim WordDoc As New Word.Document
Dim WordDoc1 As New Word.Document
Dim dialogBox As FileDialog
Set dialogBox = Application.FileDialog(msoFileDialogOpen)
'Set the display properties - these are optional
'All the settings must be applied before the .Show command
'Do not allow multiple files to be selected
dialogBox.AllowMultiSelect = False
'Set the title of of the DialogBox
dialogBox.Title = "Select a file"
'Show the dialog box and output full file path and file name
If dialogBox.Show = -1 Then
MsgBox "You selected: " & dialogBox.SelectedItems(1)
End If
Dest_File = "C:\test\test.docx"
Doc_Path = Dest_File
Set WordDoc1 = Word.Documents.Open(dialogBox.SelectedItems(1), ReadOnly:=True)
WordDoc1.Range.Copy
Set WordDoc = Word.Documents.Open(Doc_Path, ReadOnly:=True)
WordDoc.Range.PasteAndFormat wdFormatOriginalFormatting
WordDoc.ActiveWindow.Visible = True
WordDoc1.Close
End Sub