A simpler way of importing a macro

A

aine_canby

Hi all,

Is there a simpler way of importing a macro into a Visio doc without
having to go Tools > Macro > Visual Basic Editor, Import file, etc. Its
just that I have writen a macro for a client who will need to import my
macro for a number of different visio files which they have created
themselves in the past. I'd prefer if they didn't have to go through
the previous procedure in order to import the macro each time. There
must be an easier way...

Thanks very much for your help,

Aine.
 
J

John

Aine,

It's generally better practice not to place code in a document as you'll end
up with x versions of your code, which if you need to update later will have
to be done in each document. A better solution is to place the code in a
stencil that is opened with each document, thereby in one instance of your
code.

However, if you stuck with this situation for now (or you have a good reason
for putting the code in the document) then have a read through the following
article on Chip Pearson's site. It based around Excel but the process would
be basically the same for Visio.

Hope that helps

Best regards

John
 
A

aine_canby

John skrev:
Aine,

It's generally better practice not to place code in a document as you'll end
up with x versions of your code, which if you need to update later will have
to be done in each document. A better solution is to place the code in a
stencil that is opened with each document, thereby in one instance of your
code.

However, if you stuck with this situation for now (or you have a good reason
for putting the code in the document) then have a read through the following
article on Chip Pearson's site. It based around Excel but the process would
be basically the same for Visio.

Hope that helps

Best regards

John

Thanks for the suggestion John,

What I've done is added my macro to a stencil. So now I can open the
stensil, then I open the visio file for which I intend to generate the
text file for. Then I go to Tools > Macro > Macro and I must then
select the stensil name the run its macro. Of course, my visio file
must be the active document as I use Set vsoPages =
ActiveDocument.Pages in my code. Also, the key short cut won't work now
as the stensil must be active for it to trigger its macro. I was think
now that maybe I could open all the visio documents I wish to convert
to text, then make the stensil active, then have the stensils macro
loop though each visio document, printing them in turn to file. Or
maybe you have a better suggestion.

Thanks again for you help,

Aine.
 
J

John

Aine,
I'm afraid I'm not clear on what you are trying to achieve. Do you want to:

a) Import some code into each of your clients documents so that it is
available to each document every time it is opened?

or

b) Run your code on your clients documents as a one off process (ie once
this has been done once then you won't need to do it again)?

You might also want to have a look at the "Directory Process" example on the
MVP site (http://visio.mvps.org/VBA.htm)

Best regards

John
 
A

aine_canby

John skrev:
Aine,
I'm afraid I'm not clear on what you are trying to achieve. Do you want to:

a) Import some code into each of your clients documents so that it is
available to each document every time it is opened?

or

b) Run your code on your clients documents as a one off process (ie once
this has been done once then you won't need to do it again)?

You might also want to have a look at the "Directory Process" example on the
MVP site (http://visio.mvps.org/VBA.htm)

Best regards

John

b. basically, i want to choose the visio files I need text versions of
and then run a process which converts them to text. I will need to do
this multiple times considering I might update a visio file and
therefore need an updated text file - although I want to do the
conversion explicitly so that the text file is not updated
automatically every time I update the corresponding visio file.

Heres what I have working now. I open all the visio docs I wish to
convert, then I open my stencil. The stencil contains my macro. Then
with the stencil window active, I type the key shortcut for this macro.
This results in text files being produced for all the visio docs I have
open. This is pretty much what I want, but it would be more elegant for
my client if they didn't have to make active the stencil in order to
activate the macro. Is it possible to create my own button, or
something like that, at the application level, which when pressed will
activate my code and hence result in the required conversion?

Thanks again,

Aine
 
J

John

If you want to start add menus and buttons then Visio offers you two routes:
the CommandBars and the UIObject. The UIobject is the way to go but it
requires a bit of caution as it is possible to wipe out your existing UI (ie
the standard Visio interface) and / or any user specific or document
specific customisations. So read the following thoroughly!
http://msdn2.microsoft.com/en-us/library/aa201792.aspx

If you consider this to be too much of a pain, I guess another option would
be to have your code in a single document (doesn't have to be a stencil),
perhaps called something like "BatchVisioToText" that would run your code on
the DocumentOpened event. You could have a form open where the user could
point towards a directory, and then run your code for each Visio doc in that
folder. Not a perfect solution but at least it would save you from seeing
the Macros UI.

You'll have to decide, amongst other things, how often you need to run this
task, how robust you need it be and how much learning you think you can do
in the time available.

Best regards

John
 
A

aine_canby

John skrev:
If you want to start add menus and buttons then Visio offers you two routes:
the CommandBars and the UIObject. The UIobject is the way to go but it
requires a bit of caution as it is possible to wipe out your existing UI (ie
the standard Visio interface) and / or any user specific or document
specific customisations. So read the following thoroughly!
http://msdn2.microsoft.com/en-us/library/aa201792.aspx

If you consider this to be too much of a pain, I guess another option would
be to have your code in a single document (doesn't have to be a stencil),
perhaps called something like "BatchVisioToText" that would run your code on
the DocumentOpened event. You could have a form open where the user could
point towards a directory, and then run your code for each Visio doc in that
folder. Not a perfect solution but at least it would save you from seeing
the Macros UI.

You'll have to decide, amongst other things, how often you need to run this
task, how robust you need it be and how much learning you think you can do
in the time available.

Best regards

John

Great, thanks for 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