PDA

View Full Version : Solved: Visio to Word



Kindly_Kaela
01-19-2007, 08:42 AM
Hello Everyone!

I'm creating a proposal generator tool for my company's sales force. The VBA is programmed in WORD. There are several Word templates. The user's responses to the form questions determines which template opens and how to edit it.

I am in the process of creating standardized Visio's to insert in the WORD template as a .jpg. That part words great!

I see Visio has a Macro/Record function. I would like to create a Macro that customizes Visio diagrams depending on the end-users needs. And furthermore, integrate that with the Word VBA program I'm creating.

Before I begin playing in Visio, can I integrate Visio macros into the WORD VBA program? Can WORD open Visio, manipulate a diagram, save it as a .jpg, and then insert it into the Word template?

I would greatly appreciate any advice from you Visio / Word gurus.

Thanks!
Kaela
:cloud9:

lucas
01-19-2007, 08:49 AM
Hi Kaela,
I don't know anything about visio but would clarify one sentence in your question:


Before I begin playing in Visio, can I integrate Visio macros into the WORD VBA program? Can WORD open Visio, manipulate a diagram, save it as a .jpg, and then insert it into the Word template?


Do you mean the actual .dot template or the clone of the template?

Kindly_Kaela
01-19-2007, 09:02 AM
Not sure what the difference is.

Basically, I have about 10 .DOT templates stored on the network. End user answers the form questions. The answers determine which .DOT opens and it's then saved as a .DOC.

The Visio's are inserted while it's .DOT.

Does that make sense?

lucas
01-19-2007, 09:07 AM
Yes, that clears up my question. Sorry I can't help more with this. I am curious as to why your automating the creation of .dot templates. Especially if there are only 10 of them....

Bob Phillips
01-19-2007, 09:32 AM
Just a quick comment. Visio supprts VBA and automation, so you should be able to open Visio docs fromm within Word VBA and manipulate them just as easily as you could in Vision VBA - in other words, with great difficulty, because the Visio object model is hard!

I have an Excel spreadsheet which creates a job chart in sort of doughnut form using Visio, and every time I go back to it it takes me ages to remember what is going on, and how it works.

Kindly_Kaela
01-19-2007, 01:10 PM
Yes, that clears up my question. Sorry I can't help more with this. I am curious as to why your automating the creation of .dot templates. Especially if there are only 10 of them....

Hi Lucas,

We have 10 main products. I created a proposal template (.DOT) for each since they varry tremendously. Within the 10 products are several variations. So I basically created 10x .DOT's and depending on the variation requested by the end-user, paragraph's in the .DOT's are deleted.

Based on my past experience working with you brilliant programmers, I'm sure I'm doing it an unefficient way.....but it works :)

Kindly_Kaela
01-19-2007, 01:25 PM
Looks like I can at least record macros in Visio and go from there. Here's the million dollar question.

The starting VBA program is in WORD. From my WORD macro, can I open Visio and start the Visio macro? If so, what's the command?

Thanks!!
:cloud9:

Bob Phillips
01-19-2007, 04:16 PM
Opening Visio is trivial, it is just another application, but running a Visio macro is not so easy as I don't think Visio supports Application.Run. You could always have a startup macro in the Excel document, but that would just do stuff to that document, nothing is returned to the calling app. If you want to do stuff with Visio docs, I suggest that you would be better off running all the code from the Word app.

TonyJollans
01-19-2007, 07:28 PM
I don't have Visio installed at the moment but, IIRC, it has a command like "Execute" or "ExecuteLine" which will run a line of code, so you should be able to do something like:

Set appVisio = CreateObject("Visio.Application")
Set docVisio = appVisio.Documents.Open("whatever")
docVisio.ExecuteLine "Visio_Procedure_Name parameters"

Bob Phillips
01-20-2007, 04:30 AM
Tony is absolutely right, and it works



Sub RunVisio()
Dim oVisio As Object
Dim oVisioDocuments As Object
Dim oVisioDocument As Object
Dim sFile As String

sFile = "C:\personal\bob\development\Drawing1.vsd"

Set oVisio = CreateObject("Visio.Application")

With oVisio
Set oVisioDocuments = oVisio.Documents
Set oVisioDocument = oVisioDocuments.Open(FileName:=sFile)
oVisioDocument.ExecuteLine "myVisioMacro"
End With

If Not oVisio Is Nothing Then
oVisio.Quit
Set oVisio = Nothing
Set oVisioDocuments = Nothing
Set oVisioDocument = Nothing
End If
End Sub


But I stand by my earlier point that I think it is better to run it from within Word, under control.

mdmackillop
01-20-2007, 06:21 AM
Here's a link to some Visio vba and maybe some other help.
http://visio.mvps.org/VBA.htm

Kindly_Kaela
01-20-2007, 09:45 AM
Bob, I agree and would like to run it within WORD. What do you mean "control"? And will that change this code?

Thank you guys!! I'll look into your recommendations and coding first thing Monday! I can't wait...you all have inspired me once again!!

Have a nice weekend, and talk to you Monday!!

- Kaela

Bob Phillips
01-20-2007, 11:56 AM
I think what you mean by run it within Word and what I am meaning are slightly different, which revolves around my use of the word control.

What I mean is that as well as starting the proposal from within Word, if you want to do anything within Vision, or with Visio documents, I would be doing all of that from within Word. I would NOT run a macro in the Visio document, that is where I believe that you don't have the control.

The code that I gave would of course change, the code that runs the macro would be removed, and then you would need some code to do whatever it is that you want to do to the Visio document.

Zack Barresse
01-27-2007, 11:54 AM
One method you may think of using is creating the Visio instance, creating the Visio file and inserting a Visio object into Word. You'll then have the capability to open the visio file and/or update it as necessary (considering the application is installed on the local machine which you are doing this).

If this is only for your local machine, I would also think about using Early binding to the Visio OM via VBIDE | Tools | References. This will give you full access to the intellisense and OM, which will make things much easier for you.

I have both programs, so if you need some testing done, I can help out with that as well. :yes