stencil load via url on document open

Started by M.G.Ford, June 23, 2015, 03:56:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

M.G.Ford

Hi,

I am soo needy :). This question pertains to loading stencils via vba. I have a bunch of stencils that I have created containing custom shapes. I have stored the stencils on a sharepoint site. I need to be sure that when a person opens the document, the stencils are loaded. I have had mixed results with saving workspace. I have the code to load a stencil

Application.Documents.OpenEx base_location + BespokeStencil, visOpenRO + visOpenDocked

By default, it doesn't seem that Visio will load a copy of an already open stencil. This behavior is what I want. Visio will just know that the stencil is open and not load it again.

Should I explicitly code to check for an open stencil and load it if not or just leave the default behavior. I feel like I should code it because if MS changes the behavior in the future, it could break my code. The pseudo code would be (because I don't know the code checking open stencils yet)

sub load_stencil (location as string, stencil_name as string)
    if stencil_name is open
        exit sub
    else
        Application.Documents.OpenEx location + stencil_name, visOpenRO + visOpenDocked
    end if
end sub



tashik

I was having similar problems

Saving with workspace does not help.

Assuming your environment settings and permissions will allow for it, I found the solution to be:

1- File->Options->Advanced->File Locations then set "Stencils:" path to be the Sharepoint folder
2- File->Options->Trust Center->Trust Center Settings->Trusted Locations->Allow Trusted Locations on my network(not recommended)
3- File->Options->Trust Center->Trust Center Settings->Trusted Locations->Add new location... then input the path to the Sharepoint folder

(2 and 3 are for ease of use)

This essentially solved my problem, however for just in case, I eventually went with if-not-open-then-open (your second method).



M.G.Ford

Really, what we are going to do is host the .vss files on a webserver. The SharePoint is temporary. I have also found out that I have to check for an open stencil. Visio doesn't check and will double load a stencil. I am still looking for the code to do that.

M.G.Ford

right then, I got the answer worked out. since I had a hard time finding the stencil code that I was looking for and had to cobble together bits of code out there to get something workable, I thought I would share. you pass in the stencil name without the suffix (for usability). you also need to have the location of the stencil. I did this so that I can have a global variable for the location that is easy to update. you could hard code the location into the function, if you like.

base_location variable contents: http://<sharepoint_server>/Visio_stencils/ (final / is important)


Sub load_stencils(stencil_name As String, stencil_path As String)
    Dim winSrc As Visio.Window
    Dim arySrcStens() As String
    Dim win As Visio.Window
    Dim srcDoc As Visio.Document
    Dim load_stencil As Boolean
   
    stencil_name = stencil_name + ".vss"
    load_stencil = True
   
    Set srcDoc = Visio.ActiveDocument
   
    For Each win In Visio.Windows
        If win.Document Is srcDoc Then
            Set winSrc = win
            winSrc.DockedStencils arySrcStens
            Exit For
        End If
    Next
   
    Dim i As Integer
   
    For i = 0 To UBound(arySrcStens)
        If InStr(1, arySrcStens(i), stencil_name, 1) > 0 Then
            load_stencil = False
            Debug.Print "this would not load the stencil"
        End If
    Next
   
    If load_stencil Then
        Application.Documents.OpenEx stencil_path + stencil_name, visOpenRO + visOpenDocked
    End If
       
End Sub


usage example
Quotecall load_stencils ("Bpoke",base_location)

I am sure that someone could polish this a bit but it does work as is.

Michael.