redtuna
redtuna

Reputation: 4600

How can I store a shape into a variable?

The following Visio macro (using VBA) rotates the currently selected shape:

ActiveWindow.Selection.Rotate90

How can I store that shape into a variable? I tried the code below.

Dim s1 as Shape
Let s1 = ActiveWindow.Selection
s1.Rotate90

That code does not compile, it gives me a "argument not optional" error on "Selection".

If I change it to Selection(0) I get the runtime error "Invalid selection identifier".

If I try Selection(1) I get instead "Object variable or With block variable not set", which I'm guessing is VBA's way of complaining that there is only one object in the selection.

Upvotes: 0

Views: 2503

Answers (2)

Andi Allan
Andi Allan

Reputation: 35

As well as using Set instead of Let, the selection is a selection object, not a shape. You could use:

Set s1 = ActiveWindow.Selection.PrimaryItem

Upvotes: 0

Beatles1692
Beatles1692

Reputation: 5320

You should use Set instead of Let here.

Upvotes: 2

Related Questions