Shape.CellsSRCExists for a cell in a section that does not exist

Started by Visisthebest, October 21, 2023, 10:44:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

If I check for a cell in a section that may not exist, is it better to:

1. Check if the section exists first.

2. Run CellsSRCExists right away without checking if the section exists.

https://learn.microsoft.com/en-us/office/vba/api/visio.shape.cellssrcexists
Visio 2021 Professional

wapperdude

I just check for cell existing.  The section existing could be true and the cell still not exist.  I don't recall running into issue of getting error for cell exists if the section doesn't.
Visio 2019 Pro

wapperdude

Oh.  If I'm not mistaken, if a cell is added using code, but the section doesn't exist, Visio will create the section automatically.
Visio 2019 Pro

Visisthebest

Quote from: wapperdude on October 21, 2023, 04:39:59 PM
Oh.  If I'm not mistaken, if a cell is added using code, but the section doesn't exist, Visio will create the section automatically.

Thank you Wapperdude I did not know this, I always check if a section exists first then create it if needed!
Visio 2021 Professional

wapperdude

Just confirmed.  What I have done in the past is the following to check if row is present, if not, create a named row, then set value in the row.  In this case, the value become No Formula  This works fine whether or not the User section is pre-existing.  If absent, Visio does indeed add it.


    If Not vShp.CellExistsU("User.From", False) Then
        vShp.AddNamedRow visSectionUser, "From", visdefault
    End If
    vShp.CellsU("User.From").FormulaU = ""
Visio 2019 Pro

Visisthebest

There is certainly a difference with add-in behavior, if I set a non-existing User cell from a VSTO add-in I get an exception immediately.
Visio 2021 Professional

wapperdude

Good to know. 

Was the shapesheet section already existing or not?
Visio 2019 Pro

Visisthebest

Doesn't matter if the section exists but the cell doesn't, still an error. For an add-in it is better this way, because I might be misspelling a user cell name if it doesn't fail now it will fail later.
Visio 2021 Professional

wapperdude

Quoteif I set a non-existing User cell from a VSTO add-in I get an exception immediately

I re-read the above quote.  Now I'm confused. What do you mean by "set".  I took that to mean create.  But your last post sounds like you're trying to enter a value into a non-existent cell.  That will indeed fail...every time...add-in or otherwise.  It is certainly not what the code snippet does.  Since, I'm sure that you know this, I'm not sure what you mean.   Help the boy! ( or old man 😃)
Visio 2019 Pro

Visisthebest

Sorry a misunderstanding indeed, I thought you meant a cell that does not exist yet is added when writing a Formula or Result to it. That is why I was so surprised this works at all!
Visio 2021 Professional

wapperdude

Ah!  Phew!  That's one thing I'm glad Visio doesn't do!!!  😅
Visio 2019 Pro

Visisthebest

Well VisioGPT-5 will do this, in fact it will already have read your mind with the new Microsoft Surface-direct-brain-interface and added the shape cells you needed.

The future is bright ;)
Visio 2021 Professional

wapperdude

Visio 2019 Pro