0
votes

I am making a tool in Visio to draw electronic designs. When finished, theses designs should then be copied to a word document for further write up and descriptions of designs. I am struggling with the VBA code in Visio to copy the Visio page into the word document. Preferably I would open an existing word template and copy the Visio design after a given Word HEADING or so but for now I have only managed to create a new empty word document but can't find a way to reference the word document.
Could anyone help me with how to paste the selected diagram into the word application please? This the Visio code I am struggling with:

Public Sub CopyVsoPgToWord()
   Dim objWord
   Dim objDoc
   Dim vsoPage As Visio.Page
   Dim DocName As String
   
   Set objWord = CreateObject("Word.Application")
   objWord.Visible = True
   Set objDoc = objWord.Documents.Add

   ActiveWindow.SelectAll
   Application.ActiveWindow.Selection.Copy
   With objDoc
      .Paste  'this doesnt work
      'past the Visio diagram into word page 2
   End With

End Sub

1

1 Answers

0
votes

The Paste method appear on a number of classes like Range, so you just need to find one of those. The Content property of Document will give you a Range but you could change that depending on where you want to insert the object.

You might also find it easier to add a reference to the Word object model (via Tools / References / Microsoft Word).

Anyway, have a go with this:

   Dim wdApp As Word.Application
   Dim wdDoc As Word.Document
   
   Set wdApp = CreateObject("Word.Application")
   wdApp.Visible = True
   Set wdDoc = wdApp.Documents.Add("C:\Program Files (x86)\Microsoft Office\root\Templates\1033\OriginReport.Dotx")

   Dim vApp As Visio.Application
   Dim vSel As Visio.Selection
   
   Set vApp = Visio.Application
   
   Set vSel = vApp.ActivePage.CreateSelection(visSelTypeAll, Visio.VisSelectMode.visSelModeSkipSuper)
   vSel.Copy
   
   wdDoc.Content.Paste

(Your getting a Selection from the window will also work here)