5

The default Viso document has a CodeName of ThisDocument and unlike other Office documents, the ThisDocument component's CodeName appears to be Read Only.

If I have trusted access to the VBE, then I can rename the component, with a line like this:

ThisDocument.vbProject.vbComponents("ThisDocument").Name = "FooBar"

And from that point on, I can refer to the object as FooBar instead of ThisDocument

But, presumably, the CodeName is Read-Only for a reason. I can't find any issues with renaming the object, so far, but I'm unsure if there might be some unexpected ramifications.

Is it safe/wise to rename the ThisDocument component?

ThunderFrame
  • 9,352
  • 2
  • 29
  • 60
  • The first thing I'd worry about is Events - maybe do a before/after test to see if they're still hooked up correctly. – Blackhawk Feb 13 '17 at 19:36
  • @Mat'sMug this (see my answer) is also a problem in MS Word - stumbled upon this while using the awesomeness of Rubberduck *(which probably shouldn't have allowed me to rename ThisDocument to SomeThing)*. Most things seemed to work (in MS Word), except for macro buttons – SlowLearner Aug 16 '17 at 04:47

1 Answers1

2

When the double click event of a shape is linked to a macro (as described here, to create a Macrobutton of sorts) things break. Tested with Visio 2010 - 64bit version.

Furthermore after reinstating the original name of ThisDocument...

  • FooBar.vbProject.vbComponents("FooBar").Name = "ThisDocument"

... everything worked again :)

linking shapes to macro

SlowLearner
  • 3,086
  • 24
  • 54
  • This is also an issue in MS Word, however in MS Word other events still seem to work. Code for MacroButtons was simply not found *(although there might be a way)*. – SlowLearner Aug 16 '17 at 04:50
  • I can rename a word document component, but the "Sub or Function not defined" error appears until.. it doesn't, but I don't know what triggers (and can't reliably reproduce the steps) the field to refresh. In any event, a MacroButton macro shouldn't be in the document module, it should be in a standard module. With that approach, renaming the module still allows the MacroButton to find the procedure. While Visio does allow a shape's DblClick to refer to a procedure in a std module, the shape persists a module-qualified reference to the procedure, so any rename would need to update the shape. – ThunderFrame Aug 16 '17 at 11:42
  • @ThunderFrame so... the error disappears?! That's fun :-D WRT my testing in MS Word, indeed the Macrobutton Code was in a standard module. I just showed the MB code in "ThisDocument" for visio because it was less work ;-) – SlowLearner Aug 16 '17 at 11:45
  • @ThunderFrame also, not sure if you checked in Word, but you can just type over ThisDocument in the properties window. So even though it's not read only, it still breaks :( – SlowLearner Aug 17 '17 at 11:33
  • I was able to get all of the MACROBUTTON fields in Word to work again by executing `On Error Resume Next : Application.Run vbNullString`. Obvious, huh?!?!?! %^) – ThunderFrame Aug 21 '17 at 05:52
  • And recording a macro in Visio 2010, shows me that I can reassign the macro `Application.Windows.ItemEx("Drawing1:Page-1:Decision ").Activate` and then `Application.ActiveWindow.Shape.CellsSRC(visSectionObject, visRowEvent, visEvtCellDblClick).FormulaU = "RUNMACRO(""newDocName.aaaa"")"` – ThunderFrame Aug 21 '17 at 06:05
  • I'm not even going to ask how long it took you to figure out the `OERN : Application.Run vbNullstring` - it's mind blowing that you even tried it; possessed much!? – SlowLearner Aug 22 '17 at 02:31