Author Topic: Making a script working in all tabs in a visio File  (Read 2350 times)

0 Members and 1 Guest are viewing this topic.

glaffitte

  • Jr. Member
  • **
  • Posts: 10
Making a script working in all tabs in a visio File
« on: June 27, 2016, 08:39:39 AM »
Hi,

I have a piece of visio code that works, but I need to run it for every single tab within a visio file. My question is: Is there a way to have the script run for an entire visio document?

Regards
Gonzalo

Surrogate

  • Hero Member
  • *****
  • Posts: 1563
    • ShapeSheet™ Knowledge Base
Re: Making a script working in all tabs in a visio File
« Reply #1 on: June 27, 2016, 08:46:08 AM »
1. you can place that code in other visio document, which must be open when you want change target file. Use ActiveDocument instead ThisDocument
2. you can place that code in other ms office document, but there you need make some changes
3. you can create add-in with use VisualStudio
4. also you can write visual basic script, aka vbs file

glaffitte

  • Jr. Member
  • **
  • Posts: 10
Re: Making a script working in all tabs in a visio File
« Reply #2 on: June 27, 2016, 09:21:12 AM »
I have probably not expressed myself correctly...:

Sub SomethingLikeAs()
Dim sh As Shape
For Each sh In ActivePage.Shapes
    If sh.CellExists("Prop.Countreport", visExistsAnywhere) Then
        If sh.Cells("Prop.Countreport").FormulaU = """ITHB""" Then sh.Cells("Fillforegnd").Formula = visDarkRed
        If sh.Cells("Prop.Countreport").FormulaU = """ITHL""" Then sh.Cells("Fillforegnd").Formula = visDarkBlue
        If sh.Cells("Prop.Countreport").FormulaU = """ITHH""" Then sh.Cells("Fillforegnd").Formula = visDarkGreen
        If sh.Cells("Prop.Countreport").FormulaU = """ITHR""" Then sh.Cells("Fillforegnd").Formula = visDarkYellow
    End If
Next
End Sub

I have to run it basically in every single page. What I want is to change it so ir runs in the entire document - including all pages in one go.

I've tried to change ActivePage to Active Document but it wouldn't provide a good result.

Any suggestions?

Thanks in advance!


AndyW

  • Sr. Member
  • ****
  • Posts: 326
    • PC Mimic Diagram
Re: Making a script working in all tabs in a visio File
« Reply #3 on: June 27, 2016, 09:48:42 AM »
Sub SomethingLikeAs()
Dim sh As Shape
Dim vp as Visio.page
for each vp in ActiveDocument.Pages
  For Each sh In vp.Shapes
    If sh.CellExists("Prop.Countreport", visExistsAnywhere) Then
        If sh.Cells("Prop.Countreport").FormulaU = """ITHB""" Then sh.Cells("Fillforegnd").Formula = visDarkRed
        If sh.Cells("Prop.Countreport").FormulaU = """ITHL""" Then sh.Cells("Fillforegnd").Formula = visDarkBlue
        If sh.Cells("Prop.Countreport").FormulaU = """ITHH""" Then sh.Cells("Fillforegnd").Formula = visDarkGreen
        If sh.Cells("Prop.Countreport").FormulaU = """ITHR""" Then sh.Cells("Fillforegnd").Formula = visDarkYellow
    End If
  Next
Next
End Sub
Live life with an open mind

glaffitte

  • Jr. Member
  • **
  • Posts: 10
Re: Making a script working in all tabs in a visio File
« Reply #4 on: June 27, 2016, 10:10:29 AM »
Thanks a lot!!! It worked perfectly.