此函數創建一個word文檔,保存並關閉它,但在嘗試重新打開時失敗。它說這在遠程通話不起作用。重新打開單詞文檔的適當做法是什麼?還是沒有必要再關閉和打開? word和excel之間的交流似乎很困難。如何將圖表從Excel傳輸到Word
Sub tester()
Dim wordApp As Object
Dim wordDoc As Object
Dim appendDate As String
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
appendDate = "Y"
fName = "robot"
If appendDate = "Y" Or appendDate = "y" Then
fName = ThisWorkbook.Path & "\" & fName & "-" & Format(Now(), "yyyymmdd-hhmm") & ".docx"
Else
fName = ThisWorkbook.Path & "\" & fName & ".docx"
End If
wordApp.Documents.Add.SaveAs2 fileName:=fName
wordApp.Documents.Close
wordApp.Application.Quit
Set wordDoc = wordApp.Documents.Open(fileName:=fPath, readOnly:=False)
ThisWorkbook.Sheets("Sheet1").ChartObjects(1).Activate
ActiveChart.ChartArea.Copy
wordDoc.Application.Selection.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, Placement:=wdInLine
End Sub
你不需要重新創建一個對象,然後用'設置wordDoc'因爲你是對之前退出應用程序? – Dan
這是沒有必要關閉和打開你的情況。只需使用該對象,然後關閉它到底 –