我试图使用 excel 宏打开一个 word 文件并将一些数据从 excel 复制并粘贴到打开的 word 文件中。然后在excel文件的同一目录下保存为word文件。但面临错误。请帮忙。这是我的代码。
enter code here
Sub OICD()
Const strPath As String = "C:\Users\owner\Desktop\OICD TEMPLATES\OICD_"
Dim strFileName As String
strFileName = InputBox("Please enter file name", "Create new file")
If strFileName = vbNullString Then Exit Sub
Dim Word As Object: Set Word = CreateObject("word.application")
Dim docWD As Word.Document
Word.Visible = True
Set docWD = Word.Documents.Open("C:\Users\owner\Desktop\OICD TEMPLATES\OICD Template V1.docx")
docWD.SaveAs ThisWorkbook.Path & "\" & strFileName), FileFormat:=wdFormatDocument
ThisWorkbook.Sheets("REPORT").Range("C7:J56").Copy
Word.Selection.Paste
End Sub