Visio Guy

Visio Discussions => Programming & Code => Topic started by: pcoz on September 10, 2015, 11:08:52 PM

Title: set rectangle name
Post by: pcoz on September 10, 2015, 11:08:52 PM
Hi,

If I draw a rectangle this is assigned an incremental id, e.g.
    Application.ActiveWindow.Page.DrawRectangle 3, 10.2, 4.3, 9.5   'will be assigned shape id 1
    Application.ActiveWindow.Page.DrawRectangle 1, 9.2, 2.3, 8.5    'will be assigned shape id 2
    Application.ActiveWindow.Page.DrawRectangle 3, 9.2, 4.3, 8.5    'will be assigned shape id 3

Is there any way I can draw a rectangle and assign a name to it when I draw it without having to select it first?

Thanks :-)
Title: Re: set rectangle name
Post by: Paul Herber on September 10, 2015, 11:16:23 PM
dim shp as shape
shp = Application.ActiveWindow.Page.DrawRectangle 3, 9.2, 4.3, 8.5
shp.Name = "fred"
Title: Re: set rectangle name
Post by: pcoz on September 10, 2015, 11:25:15 PM
Thanks

Visio didn't like
shp = Application.ActiveWindow.Page.DrawRectangle 3, 9.2, 4.3, 8.5
(font changed to red and error: expected end of statement)

:-)
Title: Re: set rectangle name
Post by: Paul Herber on September 10, 2015, 11:27:16 PM
Ah yes, sorry, I don't normally do VBA,
Set shp = Application.ActiveWindow.Page.DrawRectangle 3, 9.2, 4.3, 8.5
Title: Re: set rectangle name
Post by: pcoz on September 10, 2015, 11:40:22 PM
Thanks

For some reasons VBA needs brackets when using Set
Set shp = Application.ActiveWindow.Page.DrawRectangle(1, 9.2, 2.3, 8.5)

:-)
Title: Re: set rectangle name
Post by: wapperdude on September 11, 2015, 02:44:28 AM
Yes, that's the correct syntax: https://msdn.microsoft.com/en-us/library/ms196001(v=office.12).aspx

Wapperdude