Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Joe7712 on September 25, 2014, 12:59:38 PM

Title: SETATREF with Shape Data causing Error 318
Post by: Joe7712 on September 25, 2014, 12:59:38 PM
Having a bit of strange behaviour with Visio today when copying a shape on a page which is from the document stencil. I have managed to find the cause but its a bit difficult to explain...

Steps to reproduce from example attached:
Setup
The page has shape data with a single fixed list dropdown field, the value of this is a SETATREF to a user-field in the document. The green box has a field which is reading the user field from the document.
The reason why it is SETATREF to the document is that I want the property to be the same on all pages.

Cause
The SETATREF sends the formula "INDEX(1,Pages[Page-1]!ThePage!Prop.List.Format)" which seems to cause this error.
There doesn't appear to be any other issues with using this technique.

Solution?
The solution would be to evaluate the result of the page shape data field, then send this value to the document user-field. So that the user field would contain just "A" rather than "INDEX..." Any ideas on the best way to do this?

Any ideas on why this is happening in the first place?
Title: Re: SETATREF with Shape Data causing Error 318
Post by: Surrogate on September 25, 2014, 01:31:20 PM
Dont store TheDoc formulaes like as INDEX(1,Pages[Page-1]!ThePage!Prop.List.Format), because it is most reason of Error #318
Title: Re: SETATREF with Shape Data causing Error 318
Post by: JohnGoldsmith on September 25, 2014, 06:42:02 PM
I think if you push a value in rather than the formula it appears to deal with the error. 

Try setting the page Shape Data cell to SETATREF(TheDoc!User.List,SETATREFEVAL(SETATREFEXPR()))

Best regards

John
Title: Re: SETATREF with Shape Data causing Error 318
Post by: Joe7712 on September 26, 2014, 10:39:44 AM
Thanks John that works perfectly! :D
Title: Re: SETATREF with Shape Data causing Error 318
Post by: JohnGoldsmith on September 26, 2014, 10:56:34 AM
Great, well Surrogate's right, it is the reference from the doc cell to the page that produces the error.

Glad you're fixed.

Best regards

John
Title: Re: SETATREF with Shape Data causing Error 318
Post by: Surrogate on September 26, 2014, 12:10:43 PM
This macro can repair your file. It replace formulae in TheDoc cell by their value
Sub vsd_RepairError318()
Dim cl As Row, ss As Window
Dim n As Integer
n = 0
Dim row_name$, row_value$, row_prompt$, new_prompt$, bl As Boolean
Set ss = Application.ActiveDocument.DocumentSheet.OpenSheetWindow
For i = ss.Shape.RowCount(242) - 1 To 0 Step -1
    row_name = Application.ActiveWindow.Shape.CellsSRC(visSectionUser, i, visUserValue).RowNameU
    row_formula = Application.ActiveWindow.Shape.CellsSRC(visSectionUser, i, visUserValue).FormulaU
    row_value = Application.ActiveWindow.Shape.CellsSRC(visSectionUser, i, visUserValue).ResultStr("")
    row_prompt = Application.ActiveWindow.Shape.CellsSRC(visSectionUser, i, visUserPrompt).FormulaU
    bl = InStr(row_formula, Trim("Pages["))
If bl = True Then '
n = n + 1
If n = 1 Then new_prompt = "setf(getref(thedoc!user." & row_name & "), " & Chr(34) & Chr(34) & Chr(34) & row_value & Chr(34) & Chr(34) & Chr(34) & ")"
If n > 1 Then new_prompt = new_prompt & "+setf(getref(thedoc!user." & row_name & "), " & Chr(34) & Chr(34) & Chr(34) & row_value & Chr(34) & Chr(34) & Chr(34) & ")"
Else
End If
Next
Debug.Print new_prompt
ActiveDocument.DocumentSheet.AddNamedRow visSectionUser, "Err318fix", visTagDefault
ActiveDocument.DocumentSheet.Cells("User.Err318fix.prompt").FormulaU = new_prompt
Application.ActiveWindow.Shape.DeleteRow visSectionUser, ActiveWindow.Shape.RowCount(242) - 1
ss.Close
End Sub
Title: Re: SETATREF with Shape Data causing Error 318
Post by: daihashi on May 03, 2015, 07:43:11 PM
I just wanted to say thanks, and to bump this post up for anyone else with a similar problem.

I had this problem, and while I did not use this code to solve it... the discussion in here pointed allowed me to identify exactly what my problem was. I went approximately 1 year with using a work-around instead.

Needless to say I feel a little dumb for not realizing the issue was that I had a dirty vss file due to converting a vsd file into a stencil file. After reading this post the problem became very obvious, and I simply deleted the excess Documentsheet user cells, and removed the documentsheet shapesheet and scratch sections entirely, and my issue was resolved instantly.

Thank you again!
Title: Re: SETATREF with Shape Data causing Error 318
Post by: Hey Ken on March 22, 2019, 08:10:58 PM

Surrogate:

   Let me add my heartfelt thanks, because today this code saved my butt.  Those pesky Powers-That-Be went and upgraded my laptop to Windows 10, and although I still have Visio 2013 Professional, all of a sudden I started getting those 318 errors every time I hit ctrl-C.  So all of a sudden the remnants of my cantankerous 500+ page screenflow (http://visguy.com/vgforum/index.php?topic=7022.0) became much more difficult to edit.  And that was Bad because I was facing an end-of-day deadline.  But I ran your macro and voila!  No errors!!

   Unfortunately, it did impact some other functionality, specifically, Metuemre's neat trick (http://visguy.com/vgforum/index.php?topic=8363.msg36221#msg36221) for referencing page names without knowing the page name.  He suggested using it in the double click shapesheet event, but me, I had to go and use it in the  document's shapesheet.  Worked fine with Windows 7, but crapped out with my new Windows 10.  Fortunately, the fix was minor, and I hit my deadline today with time to spare.

   I've said it before and I'll say it again: This forum rocks!

   - Ken


Title: Re: SETATREF with Shape Data causing Error 318
Post by: Surrogate on March 25, 2019, 01:20:47 PM
Ken, thank you for your kind words!

Code I wrote about 5 years ago. About half a year ago, I found a way as possible make copy of shape even if the document contains error 318:
Do not use Ctrl + C! Instead, select the shape and hold down the Ctrl key to pull the shape.
Therefore, you can even copy a shape to another document:
1.open two documents.
2. Arrange two windows near.
3. And same With hold Ctrl key pull the shape into another document. But not immediately on the page, but in the document Stensil of other document.
4. Drag the shape to page from own document Stencil
Title: Re: SETATREF with Shape Data causing Error 318
Post by: Hey Ken on December 15, 2020, 09:54:16 PM
Folks:

   Well, Surrogate's workaround didn't work around my latest Error 318.  But I did find a different way to work around it.

   The problem was that when I dragged a custom shape off the stencil, Visio complained with an Error 318 that a certain User Section cell wasn't there.  No idea why; the shape did not reference that cell anywhere.  I tried adding the named cell to the document's shapesheet, and that cleared up the immediate issue – but then Visio complained about a different User cell, one that had a space in the middle of the name.  Kinda difficult to add that one!

   So what I did was to open up a blank drawing and added about twenty unnamed User Section rows on the document shapesheet.  I then opened the troublesome stencil, dropped the troublesome custom shape, and it happily landed.  I then did a ctrl-C on the happy shape, then did a ctrl-V on the target page, and it landed happily there too.  Yay.  Problem solved.

   However, one unexpected thing happened.   When I dropped it, it created five User Section rows on the document's shapesheet.  Still, it did successfully drop.  I was able to copy several otherwise-troublesome custom shapes using the same trick.  Yay.

   Worked for me.  Might work for you.  I'm using Visio Professional 2016.

   - Ken