I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this
python code Exec failure: process[word.Selection.Paste] is Invalid.
from win32com import client
excel = client.Dispatch("Excel.Application")
word = client.Dispatch("Word.Application")
doc = word.Documents.Open("D:/python/My_Work/exe/word-opt/word_file.docx")
book = excel.Workbooks.Open("D:/python/My_Work/exe/word-opt/excel_file.xlsx")
char1=sheet.ChartObjects(1).Copy
doc.Bookmarks("BookMark2").Range.Select
word.Selection.Paste
doc.Save()
doc.Close()
the Same VBA code Exec OK:
Sub test()
Set dataExcel = CreateObject("Excel.Application")
Set Workbook = dataExcel.Workbooks.Open(ThisWorkbook.Path & "excel_file.xlsx")
Set Sheet = Workbook.Worksheets(1)
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = New Word.Application
WordApp.Visible = True
Set WordDoc = WordApp.Documents.Open(ThisWorkbook.Path & "word_file.docx")
Sheet.ChartObjects(1).Copy
WordDoc.Bookmarks("BookMark2").Range.Select
WordApp.Selection.Paste
WordDoc.Save
WordDoc.Close
WordApp.Quit
Set WordDoc = Nothing
Set WordApp = Nothing
End Sub
ex: File [excel_file.xlsx] in Only a chart.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…