page changed event

Started by perry59, June 10, 2021, 03:38:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

perry59

I am using the "pagechanged" event to capture the renaming of sheets in a drawing, but for my purposes it comes  up a little short.
while this event will tell me what the page is NOW named, there seems to be no  way to find what the name of the page was BEFORE the event.
I have a backend database connected to my drawings via an addin which tracks parts etc., these part references includes the name of the sheet on which they reside.
if a user renames a page I want to edit the database to change the sheet names of these part references but I see no way of doing that.
Does anyone have any ideas of a work around?
Thanks
what, me worry?

perry59

well bummer, and I see nothing in the sheet or document shapesheets that would help either :(
what, me worry?

wapperdude

The only thing that occurs to me...
1) at some point save initial page names to some dedicated shapesheet location, perhaps in User section.
2) at document close, save current page names.
3) at subsequent file openings, if there's a mismatch, ask if old name be updated.  That way,if same page changed again, there's a previous name available.

... or something like that.

Visio 2019 Pro

Nikolay

#3
Name may be okay when you just write a macro to be used like once or twice or changed when needed...
For a long-term solution, maybe you could consider using something like page ID instead of page name.
Then you don't even need to track it with page changed event, because it never changes.

perry59

Both interesting ideas, and food for thought, surely better than the crazy scheme I came up with.

As I mentioned, this is used in the context of an adding which also is linked to a backend database. I already have tables which track document names and sheet names. I could put an extra column in my sheets table for a unique ID (GUID). Then when any sheet is added to a drawing assign it a GUID (or use its internal ID) and keep it in a user cell. Anytime a sheet is renamed or deleted in the future I could compare the sheet ID's in my database to ID's in the physical drawings. But if a database project includes multiple drawings with multiple sheets that would mean opening up every drawing and going through every sheet anytime a user deletes or renames a page. I quickly realized I would be despised and nixed that idea!

I think I will try a combination of both your ideas if you don't mind. I'll give it some trial runs and let you know how it goes.
Thanks!
what, me worry?

Visisthebest

Tracking based on UniqueIDs/GUIDs is the way to go!
Visio 2021 Professional

scott

There's an application event called WindowTurnedToPage that fires whenever you change to a different page. You could use that in conjunction with the PageChanged event, e.g., use WindowTurnedToPage to write the current page name to a user cell in the page each time the page is activated, then use PageChanged to detect that the current name is different than the previous name and take whatever action you want. I've attached a diagram with a simple version of this idea that pops a message box when the new and previous names don't match.

perry59

I just did it the easy way. Made user cells for the page name and a GUID. If the user renames a sheet, it updates those cells and the database, so it never even bothers the user. Seems to be working ok so far.
Thanks all !
what, me worry?