I'm trying to cycle through numerous Visio files in a folder, all with the same naming convention. "Complex99.vsd". So I have a counter that increments in a for loop and is concatenated to the filename string. But not all filenames are actually there. Some may jump from "Complex3.vsd" to "Complex6.vsd". So if I get an error, I want it to skip the whole loop and move on.
This works for the first run through ("Complex0.vsd") isn't there, so it skips the loop. Then it gets to "Complex1.vsd" and that file isn't there either, but this time it doesn't skip all the code. I can't figure out why.
Here's my code
This works for the first run through ("Complex0.vsd") isn't there, so it skips the loop. Then it gets to "Complex1.vsd" and that file isn't there either, but this time it doesn't skip all the code. I can't figure out why.
Here's my code
Code:
Sub ComplexConsolidator()
Dim vs As Object
Set vs = CreateObject("Visio.Application")
vs.Visible = True
Dim strComplexPath As String
strComplexPath = "\\ntdt02\eis\Roles\Telecom\LAN\Team_Information\Documentation\Complex\"
Dim strFileName As String
Dim strFullPath As String
Dim strComplexPages(1000) As String
Dim intCount As Integer
Dim intToCount As Integer
Dim intFileCount as Integer
Dim strToName As String
strToName = Application.ActiveDocument.Name
Application.Windows.ItemEx(strToName).Activate
For Each pg In ActiveDocument.Pages
strComplexPages(intToCount) = pg.Name
intToCount = intToCount + 1
Next
'do trial and error, Complex1.vsd? complex2.vsd? All the way up to who
'knows what number.
[highlight]For intFileCount = 0 To 300
strFileName = "Complex" & intFileCount & ".vsd"
strFullPath = strComplexPath & strFileName
On Error GoTo ErrorHandler
vs.Documents.OpenEx strFullPath, visOpenRW + visOpenMacrosDisabled[/highlight]
For Each pgComplex In vs.ActiveDocument.Pages 'For Each in current Complex
For intCount = 0 To intToCount - 1 'For Each in Overview pages
If strComplexPages(intCount) = pgComplex.Name Then
vs.ActiveWindow.Page = vs.Application.ActiveDocument.Pages(pgComplex.Name)
vs.Application.ActiveWindow.SelectAll
vs.Application.ActiveWindow.Selection.Copy (visCopyPasteNoTranslate)
Application.Windows.ItemEx(strToName).Activate
Application.ActiveWindow.Page = Application.ActiveDocument.Pages(pgComplex.Name)
Application.ActiveWindow.SelectAll
Application.ActiveWindow.Delete
Application.ActiveWindow.Page.Paste (visCopyPasteNoTranslate)
Exit For
End If
If intCount = intToCount - 1 Then
vs.ActiveWindow.Page = vs.Application.ActiveDocument.Pages(pgComplex.Name)
vs.Application.ActiveWindow.SelectAll
vs.Application.ActiveWindow.Selection.Copy (visCopyPasteNoTranslate)
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Insert Page")
Dim vsoPage1 As Visio.Page
Set vsoPage1 = ActiveDocument.Pages.Add
vsoPage1.Name = pgComplex.Name
vsoPage1.Background = False
vsoPage1.Index = intToCount
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageWidth).FormulaU = "18.8 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).FormulaU = "13.6 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageShdwOffsetX).FormulaU = "0.125 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageShdwOffsetY).FormulaU = "-0.125 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageScale).FormulaU = "1 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageDrawingScale).FormulaU = "1 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageDrawSizeType).FormulaU = "3"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowRulerGrid, visXRulerOrigin).FormulaU = "0.8 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowRulerGrid, visYRulerOrigin).FormulaU = "4.6 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowRulerGrid, visXGridOrigin).FormulaU = "0.8 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowRulerGrid, visYGridOrigin).FormulaU = "4.6 in"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPageLayout, visPLORouteStyle).FormulaU = "1"
vsoPage1.PageSheet.CellsSRC(visSectionObject, visRowPrintProperties, visPrintPropertiesPageOrientation).FormulaU = "2"
Application.EndUndoScope UndoScopeID1, True
Application.ActiveWindow.Page.Paste (visCopyPasteNoTranslate)
End If
Next
Next
vs.Documents.Close
[highlight]ErrorHandler:
Next
[/highlight]
End Sub