followup to the find and replace 10 items at once created last Dec 2008

Started by jogjer, November 14, 2009, 03:48:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jogjer

I have simplified the macro that was originally created that seems to work better except for one small problem:  it is searching the background page.  I want to change the first for each loop to a for next loop that goes from 1 to pages.count -1.  I can create the for next loop but I don't know how to set the page to that loop's range.  I have listed below what the subroutine currently looks like:

Private Sub butSubmit_Click()
    Dim vsoPage As Visio.Page, vsoShape As Visio.Shape
   
     
    For Each vsoPage In ThisDocument.Pages
        For Each vsoShape In vsoPage.Shapes
            vsoShape.Text = Replace(vsoShape.Text, Get1, New1)
            vsoShape.Text = Replace(vsoShape.Text, Get2, New2)
            vsoShape.Text = Replace(vsoShape.Text, Get3, New3)
            vsoShape.Text = Replace(vsoShape.Text, Get4, New4)
            vsoShape.Text = Replace(vsoShape.Text, Get5, New5)
            vsoShape.Text = Replace(vsoShape.Text, Get6, New6)
            vsoShape.Text = Replace(vsoShape.Text, Get7, New7)
            vsoShape.Text = Replace(vsoShape.Text, Get8, New8)
            vsoShape.Text = Replace(vsoShape.Text, Get9, New9)
            vsoShape.Text = Replace(vsoShape.Text, Get10, New10)
        Next
    Next
    Get1 = "Enter Text"
    New1 = "Enter Text"
    Get2 = "Enter Text"
    New2 = "Enter Text"
    Get3 = "Enter Text"
    New3 = "Enter Text"
    Get4 = "Enter Text"
    New4 = "Enter Text"
    Get5 = "Enter Text"
    New5 = "Enter Text"
    Get6 = "Enter Text"
    New6 = "Enter Text"
    Get7 = "Enter Text"
    New7 = "Enter Text"
    Get8 = "Enter Text"
    New8 = "Enter Text"
    Get9 = "Enter Text"
    New9 = "Enter Text"
    Get10 = "Enter Text"
    New10 = "Enter Text"
    UserForm1.Hide

End Sub
   
I also attached the entire file.

wapperdude

Declare some counter variable, e.g., count.

Then, do your loop to increment the count variable, and set vsoPage = ThisDocument.Pages(count) -- haven't tried this, but it ought to work.

An alternative could be to leave the page loop as is, but, test the page name and jump past the executable code if page is undesired.

The SDK typically has techniques and code examples.  If you haven't downloaded it, here's a link to the equivalent, on-line content, for the V2007 SDK:  http://msdn.microsoft.com/en-us/library/ms426586.aspx.  In addition, if you just want to see a lot of VBA examples, check out John Marshall's site: http://visio.mvps.org/

HTH
Wapperdude

Visio 2019 Pro

jogjer

Couldn't get the loop to work so I tried If vsoPage.Background is true exit sub but that hung the macro.  What should I use as the condition to stop the macro?  Tried stop and end and continue but none of those worked?  Any suggestions?

jogjer

I figured out a way to solve the problem by enclosing most of the loop in the if statement checking for false of the background page, otherwise it doesn't do anything.  Thanks for your help, wapperdude.

The solution is below:


Private Sub butSubmit_Click()
    Dim vsoPage As Visio.Page, vsoShape As Visio.Shape
             
       
    For Each vsoPage In ThisDocument.Pages
        For Each vsoShape In vsoPage.Shapes
            If vsoPage.Background = False Then
              vsoShape.Text = Replace(vsoShape.Text, Get1, New1)
              vsoShape.Text = Replace(vsoShape.Text, Get2, New2)
              vsoShape.Text = Replace(vsoShape.Text, Get3, New3)
              vsoShape.Text = Replace(vsoShape.Text, Get4, New4)
              vsoShape.Text = Replace(vsoShape.Text, Get5, New5)
              vsoShape.Text = Replace(vsoShape.Text, Get6, New6)
              vsoShape.Text = Replace(vsoShape.Text, Get7, New7)
              vsoShape.Text = Replace(vsoShape.Text, Get8, New8)
              vsoShape.Text = Replace(vsoShape.Text, Get9, New9)
              vsoShape.Text = Replace(vsoShape.Text, Get10, New10)
            End If
         Next
    Next
    Get1 = "Enter Text"
    New1 = "Enter Text"
    Get2 = "Enter Text"
    New2 = "Enter Text"
    Get3 = "Enter Text"
    New3 = "Enter Text"
    Get4 = "Enter Text"
    New4 = "Enter Text"
    Get5 = "Enter Text"
    New5 = "Enter Text"
    Get6 = "Enter Text"
    New6 = "Enter Text"
    Get7 = "Enter Text"
    New7 = "Enter Text"
    Get8 = "Enter Text"
    New8 = "Enter Text"
    Get9 = "Enter Text"
    New9 = "Enter Text"
    Get10 = "Enter Text"
    New10 = "Enter Text"
    UserForm1.Hide

End Sub
   


wapperdude

Fanastic!  Take the rest of the weekend off, you've earned it!   ;D
Visio 2019 Pro