Author Topic: SETATREF with Shape Data causing Error 318  (Read 4870 times)

0 Members and 1 Guest are viewing this topic.

Joe7712

  • Newbie
  • *
  • Posts: 7
SETATREF with Shape Data causing Error 318
« on: September 25, 2014, 07:59:38 AM »
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:
  • Try copying square 1 (a simple square added to doc stencil) to see the 318 error
  • Try copying square 2 (a simple box created from the toolbar) to get no error
  • Delete the green box at the top of the page
  • Copying square 1 now works fine...
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?

Surrogate

  • Hero Member
  • *****
  • Posts: 908
    • ShapeSheet™ Knowledge Base
Re: SETATREF with Shape Data causing Error 318
« Reply #1 on: September 25, 2014, 08:31:20 AM »
Dont store TheDoc formulaes like as INDEX(1,Pages[Page-1]!ThePage!Prop.List.Format), because it is most reason of Error #318

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 342
    • John Goldsmith's visLog
Re: SETATREF with Shape Data causing Error 318
« Reply #2 on: September 25, 2014, 01: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
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

Joe7712

  • Newbie
  • *
  • Posts: 7
Re: SETATREF with Shape Data causing Error 318
« Reply #3 on: September 26, 2014, 05:39:44 AM »
Thanks John that works perfectly! :D

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 342
    • John Goldsmith's visLog
Re: SETATREF with Shape Data causing Error 318
« Reply #4 on: September 26, 2014, 05: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
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

Surrogate

  • Hero Member
  • *****
  • Posts: 908
    • ShapeSheet™ Knowledge Base
Re: SETATREF with Shape Data causing Error 318
« Reply #5 on: September 26, 2014, 07:10:43 AM »
This macro can repair your file. It replace formulae in TheDoc cell by their value
Code: [Select]
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

daihashi

  • Full Member
  • ***
  • Posts: 134
Re: SETATREF with Shape Data causing Error 318
« Reply #6 on: May 03, 2015, 02: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!

Hey Ken

  • Full Member
  • ***
  • Posts: 199
  • Just This Guy
    • The Pennsylvania Project, with Ken Krawchuk
Re: SETATREF with Shape Data causing Error 318
« Reply #7 on: March 22, 2019, 03: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 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 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


Ken V. Krawchuk
'caster

The Pennsylvania Project
Radio Podcast

10 to 11 AM Saturdays on WWDB 860 AM in Philadelphia
On demand at http://PennsylvaniaProject.com

Surrogate

  • Hero Member
  • *****
  • Posts: 908
    • ShapeSheet™ Knowledge Base
Re: SETATREF with Shape Data causing Error 318
« Reply #8 on: March 25, 2019, 08:20:47 AM »
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
« Last Edit: March 25, 2019, 12:08:12 PM by Visio Guy »