beartooth91
Board Regular
- Joined
- Dec 15, 2024
- Messages
- 76
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hello
I'm trying to merge several Visio documents and am getting the "Object doesn't support this property or method" on the line -
I'm decent with Excel vba but Visio vba seems to be a little different animal. I've tried various flavors of code for this and I'm getting the same error. Sounds like I don't understand visio objects and methods.
Entire code as follows:
Thanks for any help....
I'm trying to merge several Visio documents and am getting the "Object doesn't support this property or method" on the line -
VBA Code:
.Pages(pageCount).Copy
I'm decent with Excel vba but Visio vba seems to be a little different animal. I've tried various flavors of code for this and I'm getting the same error. Sounds like I don't understand visio objects and methods.
Entire code as follows:
Thanks for any help....
VBA Code:
Sub MergeVisioDocuments()
Dim visApp As Visio.Application
Dim sourceDocs As Variant
Dim targetDoc As Visio.Document
Dim pageCount As Integer
Dim i As Integer
' Set the Visio application object
Set visApp = CreateObject("Visio.Application")
' Get the list of source Visio documents to merge (modify as needed)
sourceDocs = Array("C:\scrap\Natrium\Working\NSS\Logic\26396-000-J3-NSS-C0001 Rev. 00A_Native DRAIN VESSEL IMMERSION HEATERS.vsdx", _
"C:\scrap\Natrium\Working\NSS\Logic\26396-000-J3-NSS-C0100 Rev. 00A_Native TRAIN A SHX 2102A 2101A PAIR.vsdx", _
"C:\scrap\Natrium\Working\NSS\Logic\26396-000-J3-NSS-C0101 Rev. 00A_Native TRAIN A SHX 2202A 2201A PAIR.vsdx")
' Create a new blank Visio document to be the target for merging
Set targetDoc = visApp.Documents.Add("")
' Loop through each source document
For i = LBound(sourceDocs) To UBound(sourceDocs)
' Open the source document
With visApp.Documents.Open(sourceDocs(i))
' Loop through each page in the source document
For pageCount = 1 To .Pages.Count
' Copy the current page to the target document
.Pages(pageCount).Copy
With targetDoc.Pages.Add
.Paste
End With
Next pageCount
' Close the source document without saving changes
.Close 'False
End With
Next i
' Save the merged document (modify as needed)
With targetDoc
.SaveAs "C:\scrap\Natrium\Working\NSS\CombinedVisioFile.vsdx"
End With
' Quit Visio application
visApp.Quit
Set visApp = Nothing
End Sub