An if/then macro

W

wizer186

I'm trying to create a macro which runs on an if/then statement. I don't
know VBA really at all, but I've been trying to piece together code from
around the net. I took this from a piece that does something entirely
different than what I want; when I plug in the values I need it doesn't work.
I'd like it to work more generally though, where I can put in "lineweight"
or what not into the right place and a value and it work.

My particular application is I want to look for a value called "contractors"
and if it's true I want that shape's outline to be dashed; otherwise (if the
value is false) then I want it solid. I'd appreciate any help with what I've
put together so far. It seems pretty simplistic to me and maybe that's why
it isn't working, but it's taken directly from a piece of code that DOES work
that isn't much more complicated...

Sub IfThen()
Dim ThisShape As Visio.Shape
For Each ThisShape In Application.ActiveWindow.Selection
If ThisShape.CellsU("Variable").ResultIU = True/False Then
Value = ThisShape.CellsU("Variable2").ResultIU
End If
Next
End Sub
 
W

WapperDude

Try this, it ought to be adaptable for your purpose:
Sub FindEngineer()
Dim shape As shape
Dim i As Integer, nRows As Integer

For Each shape In ThisDocument.Pages(1).Shapes
If shape.Master <> "Dynamic connector" Then
nRows = shape.RowCount(Visio.visSectionProp)
For i = 0 To nRows - 1
If shape.CellsSRC(Visio.visSectionProp, i,
0).ResultStr(Visio.visNoCast) = "Engineer"
shape.CellsU("LineWeight").FormulaForceU = "4 pt"
End If
Next i
End If
Next
End Sub

HTH
Wapperdude
 
W

wizer186

Thanks Dude! It looks promising.

I don't understand VBA as well as I should however, could you just quickly
explain what it's doing in there so I can adapt it?

From what I can tell you're looking for a value "Engineer" in each shape on
the page and changing the shape's line weight to pt. 4 when you find it.

My problem lies in understanding the details of how the code works.

I appreciate your help!
 
W

wizer186

Let me give you my interpretation and see if I am understanding this correctly.

You're saying for each non dynamic connector on the page, nrows is equal to
the amount of fields in each shape. I is equal to everything from 0 to nrows
-1

The next part is where I'm completely lost (assuming I have the rest
correct...)

If shape.CellsSRC(Visio.visSectionProp, i,
0).ResultStr(Visio.visNoCast) = "Engineer"

If whatever that is equals engineer then you're forcing the lineweight to 4
pt.

I don't really understand the "i" variable I think is the problem. Then
again I might have to ALL wrong haha
 
W

WapperDude

Actually, you have it correct. Since, it's not clear whether these are
custom shapes or MS shapes, nor is it clear where "Engineer" will appear, I
step thru all of the rows, hence, the i variable, in the Property section,
searching for the value cell = Engineer. When that happens, yes, I set the
line weight to 4 pt. If you know for a fact which row would have
"Contractor", in your case, you could hard code the cellsSRC indices. I've
got to run to a meeting, if you want, I can send a link to cellsSRC later.
 
W

wizer186

I see. Makes sense. Yeah if you could send that to me that'd be great.
Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top