Issue with variables (no reset?)

Started by dorensanz, February 06, 2017, 01:19:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dorensanz

This one is kind of wierd.. I'm writting a macro to process all pages of hundreds of Visio files. I made a sub with a Do-While loop to open each Visio document of a directory process the files (3 subs), save and close.

I made some tests and the first file workks fine, but the rest not completely. I think it might be an isse with the variables, maybe not reseting or something.

Any clue what this could be? See below my Main sub and the others.

--
Sub MyMacro()
    Dim file
    Dim path As String
    Dim vsd As String
       
    path = "X:\VSD-repo\"
    file = Dir(path & "*.vsd")
    vsd = path & file
   
    On Error Resume Next
    Do While file <> ""
        Documents.Open FileName:=path & file
        Call Process1(vsd)
        Call Process2(vsd)
        Call Process3(vsd)
        ActiveDocument.Save
        ActiveDocument.Close
        file = Dir()
    Loop
End Sub
--


In the Subs I have someting like this (similar in the 3):

--
Sub Process1(VSDpath As String)
    Dim vsoShapes As Visio.Shapes
    Dim vsoShape As Visio.Shape

    For Each pagobj In ActiveDocument.Pages
        Application.ActiveWindow.Page = pagobj
        Set vsoShapes = Application.ActiveWindow.Page.Shapes
        On Error Resume Next
        For Each vsoShape In vsoShapes
          ...
        Next
    Next
End Sub
--

dorensanz

Forgot to mention. If I run the macro directly in the second visio file it works. That's why I thought a var reset could be the issue.

dorensanz

One more thought: Maybe I'm processing 3 times a loop For-Each pages in active document... But why is it working then in the first file and not in the next ones? Hmmm I'm stacked sorry.

Yacine

It would help to know what isn't working.
Go step by step through the macro and check which line is failing.
Yacine

dorensanz

It's Replace statement (Visio 2013):

vsoShape.ReplaceShape Application.Documents.Item(VSDpath).Masters.ItemU("Metric")

The procedure works for the first Visio file in the loop, but not for the next ones. However, If remove the first file from the directory, the procedure works again for the first one (former second) and not fot the next ones.


dorensanz

I got the solution. Very easy! I was not updating the vsd in the loop, I just intialitzed it before the Do While started. So if the line vsd = path & file is placed in the loop everything works!

Piece of cake! Thanks for your support