Visio 2 word

ChatGPT

import win32com.client as win32

# Open the Visio diagram and select the portion you want to copy
visio = win32.gencache.EnsureDispatch('Visio.Application')
doc = visio.Documents.Open('C:\\path\\to\\visio\\file.vsdx')
page = doc.Pages.Item(1)
selection = page.CreateSelection(visio.visSelTypeAll)

# Copy the selection to the clipboard
selection.Copy()

# Open the Word document and paste the clipboard contents as an embedded Visio object
word = win32.Dispatch('Word.Application')
doc = word.Documents.Open('C:\\path\\to\\word\\document.docx')
doc.Activate()
word.Selection.PasteSpecial(Link=False, DataType=win32.constants.wdPasteEnhancedMetafile)

# Save and close the Word document and Visio diagram
doc.Save()
doc.Close()
visio.Quit()