Need Help with Grid Origin Macro I wrote

C

CalgaryBob

Hi All,

I have written a macro to set the Grid Origin (Either Vertical or
Horizontal) to the X-Position or Y-Position of a selected Shape.

It works well if the selected Shape is of the type that uses only a single X
and Y Co-ordinate, but if I try to run the macro when the selected shape uses
Begin X, End X and Begin Y, End Y Co-ordinates, I get an error, and a pop-up
to allow debugging of the macro.

This in itself is not a problem, but the Undo command no longer works after
the error is encountered, the only way to get Undo to work is to close the
Visio App.

The macros I'm using are shown below, I'm hoping someone could show me how
to modify the nacro to avoid the error by using some sort of error checking"


MACROS:

Sub Guide_Set_Vertical()
' Keyboard Shortcut: Ctrl+Shift+X
'

Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Ruler & Grid")
Dim vsoShape1 As Shape
Set vsoShape1 = Application.ActiveWindow.Page.PageSheet
'ID = Application.ActiveWindow.Selection.Item(1).

temporigin =
Application.ActiveWindow.Selection.Item(1).CellsSRC(visSectionObject,
visRowXFormOut, visXFormPinX).FormulaU

vsoShape1.CellsSRC(visSectionObject, visRowRulerGrid,
visXGridOrigin).FormulaU = temporigin
Application.EndUndoScope UndoScopeID1, True

End Sub
Sub Guide_Set_Horizontal()
' Keyboard Shortcut: Ctrl+Shift+Y
'
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Ruler & Grid")
Dim vsoShape1 As Shape
Set vsoShape1 = Application.ActiveWindow.Page.PageSheet
'ID = Application.ActiveWindow.Selection.Item(1).

temporigin =
Application.ActiveWindow.Selection.Item(1).CellsSRC(visSectionObject,
visRowXFormOut, visXFormPinY).FormulaU
vsoShape1.CellsSRC(visSectionObject, visRowRulerGrid,
visYGridOrigin).FormulaU = temporigin
Application.EndUndoScope UndoScopeID1, True
End Sub
Sub GridOnOff()
' Keyboard Shortcut: Ctrl+g
'

Application.ActiveWindow.ShowGrid = Not Application.ActiveWindow.ShowGrid
Application.ActiveWindow.ShowGuides = Not
Application.ActiveWindow.ShowGuides

End Sub
 
P

Paul Herber

Hi All,

I have written a macro to set the Grid Origin (Either Vertical or
Horizontal) to the X-Position or Y-Position of a selected Shape.

It works well if the selected Shape is of the type that uses only a single X
and Y Co-ordinate, but if I try to run the macro when the selected shape uses
Begin X, End X and Begin Y, End Y Co-ordinates, I get an error, and a pop-up
to allow debugging of the macro.

Rather than allow an error to occur you could check whether the cell exists using the
CellExists property on the BeginY cell:
http://msdn.microsoft.com/en-us/library/aa215155(office.11).aspx

or use the OneD propery to dertmine whether it is a 1D or 2D shape.
 
C

CalgaryBob

Paul Herber said:
Rather than allow an error to occur you could check whether the cell exists using the
CellExists property on the BeginY cell:
http://msdn.microsoft.com/en-us/library/aa215155(office.11).aspx

or use the OneD propery to dertmine whether it is a 1D or 2D shape.



--
Regards, Paul Herber, Sandrila Ltd.
Electronics for Visio http://www.sandrila.co.uk/visio-electronics/
Electrical for Visio http://www.sandrila.co.uk/visio-electrical/
Electronics Packages for Visio http://www.sandrila.co.uk/visio-electronics-packages/
.

Thank You Very much Paul, your response helped me get the problem solved.

You are a great asset to this forum!
 
P

Paul Herber

Thank You Very much Paul, your response helped me get the problem solved.
You are a great asset to this forum!

Thank you for your kind words. CalgaryBob!
 

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