Adding Toolbar button via stencil libary...

G

garet

hi all,
to make my documents smaller and my code more portable I moved my code into
my stencil libary. my procedures seem to work however accessing them seems
to be a problem. for example I used the macro shortcut tool, however the
shortcuts don't seem to work. so I though I would add a toolbar button via
the document open method of the visio stencil libary. however that did not
work. it works when I load it into the drawing (document open method).

any ideas? thanks in advance for your help!
 
J

junethesecond

In stencil, "ThisDocument" means the stencil itself, the drawing page is
"ActiveDocument".
So, the event procedure, should be made by keyword,"WithEvents". that
is...
Private WithEvents myDocument As Document
Private Sub Document_DocumentOpened _
(ByVal doc As IVDocument)
Set myDocument = ActiveDocument
End Sub
Private Sub myDocument_DocumentOpened _
(ByVal doc As IVDocument)
MsgBox doc & "opened!"
End Sub
 
G

garet

Hi June,
thank you for the quick reply, I figured I would have to wait a couple of
days.

I'm not familiar with the withevents procedure so I did some reading.
From what I got the withevents needs to be in a class module. So I created
one and placed the private statement in there.

I then copied the other two subs to the new class module(which did not seem
to work) I moved them to the thisdocument page. where it did not work. I
suspect I am missing something so I will continue to read more. I do
appreciate the assist and direction.

Thank you again for your help!!!!
 
J

junethesecond

Sorry, "ActiveDocument" must be
a drawing already exists, so the
open events of ActiveDocument
does not work to the document
that will open in future.
Please, try next sample on "ThisDocument".
WithEvents can be stated on ThisDocument, too.
If you wish to put it on your own class,
something should be modified.
Private WithEvents MyDocs As Documents
Private Sub Document_DocumentOpened _
(ByVal doc As IVDocument)
Set MyDocs = Documents
End Sub
Private Sub Document_DocumentSaved _
(ByVal doc As IVDocument)
Set MyDocs = Documents
End Sub
Private Sub MyDocs_DocumentOpened _
(ByVal doc As IVDocument)
MsgBox doc & "opened!!"
End Sub
 
G

garet

Hi June,
I was able to get my menu buttons to appear. Unfortunately I am unable to
get them to do anything. I am pretty sure they are referring to the Visio
drawing procedures and not the VSS procedures. Tested by writing a function
with the same name in the same module (as the VSS) in the drawing and they
worked. Unfortunately I am trying to get them to refer to the VSS
procedures. I have tried several methods to get them to refer to the VSS
procedures but no success.

I used this procedure from MS:
CntrlType_Example1
http://msdn.microsoft.com/library/d...s/vissdk11/html/viproCntrlType_HV81900448.asp

I added the following line, which referred to the Visio drawing:
AddOnName = "module1.burp"

So I tried this (and 100's other variations)
..AddOnName = "flr_plan!module1.module1.burp"

I know what the problem is, it is referring to Visio drawing and not the VSS
(project name)

Any ideas? I tried:
..AddOnName = CALLTHIS("Module1.burp", "C:\Documents and Settings\garet\My
Documents\My Shapes\flr plan.vss")

I am not sure what else to try. I know it is a reference problem but I am
stuck.

thanks in advance for your help!

Regards,
Garet
 
G

garet

Hi June,
Well I found an interesting work around. Although I am not sure it is what
is the proper way of handling it. I added a reference from my
template/drawing to my VSS. And now it can find my code. I would imagine
that if the stencil is not available it will cause an error message. This
hardly seems to be an elegant solution but it will work for now.

Thank you again for all your help. If you should have any other
ideas/recommendation please let me know.

Regards,
Garet
 
G

garet

Hi June,
Followup to my previous email. I had to programmically add the reference
(it kept disappearing). The code is as follows (since other people might be
following this).

In the VSS ThisDocument area:
Set vbProj = ActiveDocument.VBProject
vbProj.References.AddFromFile "C:\visio std\tri-m flr plan.vss"

Although I had to lower my security to Medium and change Trusted Sources to:
Trust access to Visual Basic Project

Next stop, how to sign these things to make it more secure so I do not
expose myself.

Thanks again for all your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top