Consulting

Results 1 to 14 of 14

Thread: Solved: Visio to Word

  1. #1

    Solved: Visio to Word

    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

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    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?

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.

  6. #6
    Quote Originally Posted by lucas
    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

  7. #7
    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!!

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.

  9. #9
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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:
    [VBA]
    Set appVisio = CreateObject("Visio.Application")
    Set docVisio = appVisio.Documents.Open("whatever")
    docVisio.ExecuteLine "Visio_Procedure_Name parameters"
    [/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Tony is absolutely right, and it works

    [vba]

    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
    [/vba]

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

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Here's a link to some Visio vba and maybe some other help.
    http://visio.mvps.org/VBA.htm
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #12
    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

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.

  14. #14
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •