Visio Guy

Visio Discussions => Programming & Code => Topic started by: huever on October 15, 2019, 06:42:09 AM

Title: FILENAME() Shapesheet function does not update
Post by: huever on October 15, 2019, 06:42:09 AM
Hello,

I am trying to use the name of an open Visio file in a property of one of my shapes on Visio Drawing in order to show it on the drawing.


I observed such behaviour: when I save and close the file and then I change the name of the file the actual Value of my Identifier property does not change unless I enter the Shapesheet and go to Value cell pressing <Enter> key. I would like to do it this way that when the name of the file changes some shapes' properties on my drawing also change accordingly without any updating (entering Shapesheet and typing the "FILENAME()" formula again).

Is that possible to do it? So "FILENAME()" automatically changes value when the file is being open with a new name.

I found out that when I save the file as .vsd not .vsdx it works as expected (after opening the file the cells update themselves). The problem occurs only when saving to .vsdx format..

Thanks for your support. I attached a testing file (when it is opened the Idendifier property value does not follow the real file name).
Title: Re: FILENAME() Shapesheet function does not update
Post by: Surrogate on October 15, 2019, 01:51:10 PM
Why you ask about this issue in Programming and code chapter?
You can use vsd-documents, why you need save it in vsdx?
Title: Re: FILENAME() Shapesheet function does not update
Post by: huever on October 15, 2019, 04:05:23 PM
I'm sorry if this is the wrong place to ask.
I need to save files in vsdx, because, for example they are large and it is easier to work with them when saved as .vsdx.
Title: Re: FILENAME() Shapesheet function does not update
Post by: vojo on October 15, 2019, 04:24:22 PM
probably should try DEPENDSON to trigger filename() refresh

filename() + dependson(<some cell that changes regularly...color or locx...maybe time() works as well>)
Title: Re: FILENAME() Shapesheet function does not update
Post by: Yacine on October 15, 2019, 05:33:58 PM
@Surrogate, come on don't be so picky. We don't really care about the right category. Do we?  :D мир


@huever,

I checked your file and noticed that the shape was not prepared as it should have (inserted field) and the font colour was set to white.

Well so far. Correcting the shape, by inserting DIRECTLY the field as text - not via the according prop field - showed no problem so ever  (Visio 2016 on Windows 10).
(Select the shape, hit F2, go to menu point "insert" and choose "field", under file properties choose "filename".

Cheers, Y.
Title: Re: FILENAME() Shapesheet function does not update
Post by: Surrogate on October 15, 2019, 08:03:43 PM
I just intrested which way huever want use ! In one organization where i worked in 2005-2010 VBA was prohibited.
May be he have same limitation ?

Two weeks ago i suggest update field value in that thread (https://social.technet.microsoft.com/Forums/office/en-US/a40c1b26-4385-490e-923e-986c8841f6aa/filename-shapesheet-function-does-not-update?forum=visiogeneral).
Title: Re: FILENAME() Shapesheet function does not update
Post by: wapperdude on October 16, 2019, 12:54:43 AM
Visio 2019 works fine too.  The problem with using shape property is that will not pickup the filename change.  It is looking for a user input.  You can use technique suggested by Yacine.  If you want an intermediate step for reference purposes, create a User Defined entry, value = FILENAME(), and then insert Field > User Defined entry.  Either way works fine, though, for displaying filename.
Title: Re: FILENAME() Shapesheet function does not update
Post by: huever on October 16, 2019, 05:52:02 AM
"The problem with using shape property is that will not pickup the filename change."

- That is exactly the issue.

Thanks for your answers, I will try to do it with inserting Text Field and User Defined entry  :)

Sorry again for posting in wrong section.
Title: Re: FILENAME() Shapesheet function does not update
Post by: Croc on October 16, 2019, 07:50:44 AM
QuoteCorrecting the shape, by inserting DIRECTLY the field as text
Visio 2013, Windows 7 - function does not work. (See animated gif)
---
GIF doesn't work? I also posted it in DropBox -  https://www.dropbox.com/s/3tmv0lik52fj75w/FileNameBag.gif?dl=0
Title: Re: FILENAME() Shapesheet function does not update
Post by: Croc on October 16, 2019, 09:19:35 AM
Visio 2019, Windows 10. Similarly, the function is lying after manually renaming the file. Save does not fix the situation. SaveAs corrects.
------------
Updated
I suggest replacing the line in the description of the function
"Returns a document's file name as a string."
per line
"SOMETIMES returns a document's file name as a string. The function stops working after manually renaming the file and restores after saving the file under a different name."
Trying to trick Visio with = SETF ("User.FileName", "FILENAME ()") is futile.
You may try to use the reference to TheDoc!User.Filename instead of FILENAME (), and rewrite the formula in TheDoc!User.Filename programmatically when you open the document.
Private Sub Document_DocumentOpened (ByVal doc As IVDocument)
    ActiveDocument.DocumentSheet.Cells ("User.FileName"). FormulaU = """FILENAME ()"""
    ActiveDocument.DocumentSheet.Cells ("User.FileName"). FormulaU = "FILENAME ()"
End sub
Title: Re: FILENAME() Shapesheet function does not update
Post by: vojo on October 16, 2019, 12:48:02 PM
have fun

works on 2013
Title: Re: FILENAME() Shapesheet function does not update
Post by: huever on October 16, 2019, 04:38:13 PM
I have Visio 2019, Windows 10. This is exactly as Croc says. The only solution I found is to programatically rewrite the formulas in the cells.
Do something like (pseudocode):

string s = cell.Formula
cell.Formula = ""
cell.Formula = s

Then it updates. But with vsd format it was quite intuitive - I could extract some part of the file name and after updating the name of the file (manually, in Windows Explorer) and opening the Visio Document again I could see the data refreshed everywhere. Now I have to run a macro to have this effect. I tried SETF, User Defined cell, Insert Text Field.. Ofc I can always run some macro to do it, but I can't save the file with the macro (I  need to remember to delete it) due to policy we have (file will be considered as potentially unsafe..).

:(
Title: Re: FILENAME() Shapesheet function does not update
Post by: Croc on October 16, 2019, 06:25:20 PM
You can try the option without a program.
In one cell we make the minute timer, but we distinguish only even and odd values.
With an even value, we write a function, with an odd value, its value.
Very cumbersome, but it works :)

Scratch.A1=IF(Scratch.C1=0,SETF("Fields.Value","FileName()"),SETF("Fields.Value",GetVal(Fields.Value)))+DEPENDSON(Scratch.B1)
Scratch.B1=NOW()
Scratch.C1=1
Scratch.D1==IF(GetVal(Scratch.C1)>0,SETF(GetRef(Scratch.C1),"0"),SETF(GetRef(Scratch.C1),"1"))+DEPENDSON(Scratch.B1)
Title: Re: FILENAME() Shapesheet function does not update
Post by: wapperdude on October 16, 2019, 06:40:09 PM
After watching Croc's GIF, went back and was able to confirm that changing filename externally in FileExplorer will not be caught by the NAME() fcn.  Didn't occur to me to try this case, initially.  Note, if you delete the shape text and re-insert the NAME() fcn, it does update and show the correct value.
Title: Re: FILENAME() Shapesheet function does not update
Post by: wapperdude on October 17, 2019, 05:19:29 AM
Alternative work-around...
Create a User-Defined entry, say Row_3...or something meaningful.  Do not populate the value.
In the Dbl Click event cell, enter:  =SETF(GetRef(User.Row_3),"FILENAME()")

Dbl clicking the shape will place the Filename formula into the User Defined cell.  It will catch whatever the current name of the file, even if it were a file created externally in Window Explorer.
You can field insert the UD entry as text, or use it as reference else where.
Title: Re: FILENAME() Shapesheet function does not update
Post by: Surrogate on October 17, 2019, 06:26:53 AM
Quote from: wapperdude on October 17, 2019, 05:19:29 AMAlternative work-around...
Another one:
in some user-defined cell place formula with condition which must update FILENAME value
IF(0=0,SETF(GetRef(User.Row_3),FILENAME()),SETF(GetRef(User.Row_3),FILENAME()))
Title: Re: FILENAME() Shapesheet function does not update
Post by: Croc on October 17, 2019, 07:53:03 AM
Surrogate, are you sure?
This formula does not work for me.
Title: Re: FILENAME() Shapesheet function does not update
Post by: Surrogate on October 17, 2019, 08:05:24 AM
Not, sure. It is just suggest. I use Visio 2003 and haven't problems with update value in this field.   8)
Because i can't use vsdx-files!

UPDATE: i check my formula again, really it dont work. New modification  - wrap FILENAME() in commas.
IF(0=0,SETF(GetRef(User.Row_3),"FILENAME()"),SETF(GetRef(User.Row_3),"FILENAME()"))
Title: Re: FILENAME() Shapesheet function does not update
Post by: vojo on October 17, 2019, 01:32:44 PM
I guess I am obtuse, since I don't think this formula should actually work

Essentially, you are saying if(true, do this, do that)....but should never get to the do that since 0=0 is  ALWAYS true
(if you really don't care about else branch, you can have only a ...,) ending ...don't need an explicit else clause)
(BTW, might want to use if (true,...,...) or if(1,....,...) or if(1=1,...,...)vs if(0=0,...,...) ...it would be more obvious to reader)
More over, the only way this fires is if there is a change in filename()...but if filename changes are not caught in the first place, why would this fire?  VISIO will NOT just arbitrarily walk blindly thru every cell...it only evaluates a cell  if there is some change to the cells inputs...here filename (imagine walking thru 20 shapesheets * 100 cells in order to find the 1 cell with a change).

Sort of why I suggested DEPENDSON to make sure this cell is periodically reevaluated.  Basically, if I understand the requirements, you will need some trigger to force cell evaluation.  Don't like DEPENDSON, fair enough, you can set up a trigger a different way (2 user cells for old and new ===> new becomes old if a change, actions, could use the time() function since it always changes , could even see if there is a DOCMD command that could be used as a trigger some cell change)

maybe something like user.filename = filename() + now()   This would force the cell to be reevalutated every second because now() is always changing

Good luck
Title: Re: FILENAME() Shapesheet function does not update
Post by: huever on October 17, 2019, 06:36:24 PM
Quote from: Croc on October 16, 2019, 06:25:20 PM
You can try the option without a program.
In one cell we make the minute timer, but we distinguish only even and odd values.
With an even value, we write a function, with an odd value, its value.
Very cumbersome, but it works :)

Scratch.A1=IF(Scratch.C1=0,SETF("Fields.Value","FileName()"),SETF("Fields.Value",GetVal(Fields.Value)))+DEPENDSON(Scratch.B1)
Scratch.B1=NOW()
Scratch.C1=1
Scratch.D1==IF(GetVal(Scratch.C1)>0,SETF(GetRef(Scratch.C1),"0"),SETF(GetRef(Scratch.C1),"1"))+DEPENDSON(Scratch.B1)


Wow, I wouldn't invent it myself, but this solution actually WORKS. I open the drawing and the name is updated. Seems a bit crazy, but successful!

Thanks a lot for your answers, now I know how to workaround the problem  :)
Title: Re: FILENAME() Shapesheet function does not update
Post by: Croc on October 17, 2019, 07:00:53 PM
vojo suggested a simpler solution
Check it out too
Title: Re: FILENAME() Shapesheet function does not update
Post by: huever on October 18, 2019, 05:55:59 AM
Yes, that way it works too. I did something like this:

User.Row_1.Value = FILENAME()

User.Row_2.Value = =IF(FILENAME()=User.Row_1,FILENAME(),FILENAME())

Then I display User.Row_2 -> works also perfectly ;)

Thanks, again for your quick help!  ;)