0
我試圖用excel宏打開word文件& copy &將一些數據從excel粘貼到打開的word文件中。然後以另存爲 word文件中的相同的目錄的excel文件。但面臨錯誤。請幫忙。 這是我的代碼。使用excel生成word文件在excel同一目錄中vba
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
'面臨errors'?什麼樣的錯誤?哪裏?你需要在你的問題上更具體。 –