open visio in Excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joemo2003
    New Member
    • Feb 2007
    • 142

    open visio in Excel

    I created a button in excel sheet, and that button need to browse and open a visio drawing. I try two ways to do it, but either way work. can anyone help?

    First way:

    Private Sub CommandButton1_ Click()
    Dim objVisio As Visio.Applicati on
    Set objVisio = New Visio.Applicati on
    objVisio.Visibl e = True
    Dim vFile As Variant
    vFile = objVisio.Docume nts.Open("All Visio Files (*.vs*; *.v?x)")
    If vFile <> False Then
    Dim vsobj As Visio.Document
    Set vsobj = objVisio.Docume nts.Add(vFile)
    End If
    End Sub

    Second way:

    Private Sub button1_click()
    Dim objVisio As Visio.Applicati on
    Set objVisio = New Visio.Applicati on
    objVisio.Visibl e = True
    Dim uiObj As Visio.UIObject
    Set uiObj = objVisio.BuiltI nToolbars(0)
    End Sub
  • joemo2003
    New Member
    • Feb 2007
    • 142

    #2
    I mean both way not work.

    Comment

    • joemo2003
      New Member
      • Feb 2007
      • 142

      #3
      Originally posted by joemo2003
      I mean both way not work.
      someone help

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        Originally posted by joemo2003
        I created a button in excel sheet, and that button need to browse and open a visio drawing. I try two ways to do it, but either way work. can anyone help?
        Your first way looks almost correct, but you want to use Excel's Application.Get OpenFileName instead of objVisio.Docume nts.Open. I don't have Visio here to test it. Reply back if you still have problems: I can test it at home tonight. --Sam

        Comment

        • joemo2003
          New Member
          • Feb 2007
          • 142

          #5
          Originally posted by SammyB
          Your first way looks almost correct, but you want to use Excel's Application.Get OpenFileName instead of objVisio.Docume nts.Open. I don't have Visio here to test it. Reply back if you still have problems: I can test it at home tonight. --Sam
          I try GetOpenFileName before, GetOpenFileName not support visio.

          Comment

          • SammyB
            Recognized Expert Contributor
            • Mar 2007
            • 807

            #6
            Originally posted by joemo2003
            I try GetOpenFileName before, GetOpenFileName not support visio.
            GetOpenFileName is an Excel interface to get a FileName. If you are running Excel, then Application.Get OpenFileName will pop-up a dialog that looks like a File Open; however, it does not open anything. It returns a variant that contains the filename that the user selected or False if the user pressed Cancel. Notice how I used it in an eariler response to you, http://www.thescripts.com/forum/post2432069-18.html.
            You, then, use this variant in the Visio.Documents .Add as the chart to open.

            Comment

            • joemo2003
              New Member
              • Feb 2007
              • 142

              #7
              Originally posted by SammyB
              GetOpenFileName is an Excel interface to get a FileName. If you are running Excel, then Application.Get OpenFileName will pop-up a dialog that looks like a File Open; however, it does not open anything. It returns a variant that contains the filename that the user selected or False if the user pressed Cancel. Notice how I used it in an eariler response to you, http://www.thescripts.com/forum/post2432069-18.html.
              You, then, use this variant in the Visio.Documents .Add as the chart to open.
              I got what you mean, but it just not working:

              Private Sub CommandButton1_ Click()
              Dim objVisio As Visio.Applicati on
              Set objVisio = New Visio.Applicati on
              objVisio.Visibl e = True
              Dim vFile As Variant
              vFile = objVisio.GetOpe nFileName("All Visio Files (*.vs*; *.v?x)")
              If vFile <> False Then
              Dim vsobj As Visio.Document
              Set vsobj = objVisio.Docume nts.Add(vFile)
              End If
              End Sub

              Comment

              • SammyB
                Recognized Expert Contributor
                • Mar 2007
                • 807

                #8
                GetOpenFileName is an EXCEL object. Use Application.Get OpenFileName(.. .)

                Comment

                • joemo2003
                  New Member
                  • Feb 2007
                  • 142

                  #9
                  Originally posted by SammyB
                  GetOpenFileName is an EXCEL object. Use Application.Get OpenFileName(.. .)
                  I tried:
                  vFile = objVisio.Applic ation.GetOpenFi leName("All Visio Files (*.vs*; *.v?x)")
                  vFile = objVisio.visio. GetOpenFileName ("All Visio Files (*.vs*; *.v?x)")
                  vFile = Application.Get OpenFileName("A ll Visio Files (*.vs*; *.v?x)")
                  vFile = Visio.GetOpenFi leName("All Visio Files (*.vs*; *.v?x)")

                  They all said Object don't support this property or method.

                  Comment

                  • SammyB
                    Recognized Expert Contributor
                    • Mar 2007
                    • 807

                    #10
                    Third one is close, but should be
                    Code:
                    vFile = Application.GetOpenFilename("All Visio Files (*.vs*;*.v?x), *.vs*;*.v?x")

                    Comment

                    • joemo2003
                      New Member
                      • Feb 2007
                      • 142

                      #11
                      Originally posted by SammyB
                      Third one is close, but should be
                      Code:
                      vFile = Application.GetOpenFilename("All Visio Files (*.vs*;*.v?x), *.vs*;*.v?x")
                      Yeah, it do work. thanks

                      Comment

                      • SammyB
                        Recognized Expert Contributor
                        • Mar 2007
                        • 807

                        #12
                        Fantastic! (¬_¬)/¯

                        Comment

                        • joemo2003
                          New Member
                          • Feb 2007
                          • 142

                          #13
                          Originally posted by SammyB
                          Fantastic! (¬_¬)/¯
                          Sam,
                          Hope you see this message.
                          after i open the visio drawing, i need to input text to it. It work when:
                          Set vsPage=vsDoc.Pa ges(1)
                          but what i want is input text to the active page, so i try:
                          Set vsPage=vsDoc.ac tivepage
                          Set vsPage=vsApp.vs Doc.activepage
                          Set vsPage=vsApp.ac tivepage
                          Set vsPage=vsApp.ac tivewindow.acti vepage
                          However, they all are not working, do u know what is wrong?

                          Thanks

                          Comment

                          • SammyB
                            Recognized Expert Contributor
                            • Mar 2007
                            • 807

                            #14
                            Originally posted by joemo2003
                            Sam,
                            Hope you see this message.
                            after i open the visio drawing, i need to input text to it. It work when:
                            Set vsPage=vsDoc.Pa ges(1)
                            but what i want is input text to the active page, so i try:
                            Set vsPage=vsDoc.ac tivepage
                            Set vsPage=vsApp.vs Doc.activepage
                            Set vsPage=vsApp.ac tivepage
                            Set vsPage=vsApp.ac tivewindow.acti vepage
                            However, they all are not working, do u know what is wrong?

                            Thanks
                            Sorry, no Visio here, I'll try tonight. The only thing that I have used is what worked for you, Set vsPage=vsDoc.Pa ges(1). Maybe when you open the document, there is no active page, but that seems strange. From Help: "The ActivePage property returns a Page object only when the active window displays a drawing page; otherwise, it returns Nothing. To verify that a page is active, use the Is operator to compare the ActivePage property with Nothing."

                            So, you probably want (not tested)
                            Code:
                            	If vsApp.ActivePage Is Nothing Then
                            		Set vsPage = vsDoc.Pages(1)
                            	Else
                            		Set vsPage = vsApp.ActivePage
                            	End If
                            Here's some other code that worked for me that may help you.
                            Code:
                            	Dim vsApp As Visio.Application
                            	Dim vsDoc As Visio.Document
                            	Dim vsPage As Visio.Page
                            	Dim vsWindow As Visio.Window
                            	Set vsApp = CreateObject("Visio.Application")
                            	Set vsDoc = vsApp.Documents.Add("basic shapes.vss")
                            	Set vsPage = vsDoc.Pages(1)
                            	Set vsWindow = vsPage.OpenDrawWindow
                            	vsApp.Windows.Arrange visArrangeTileVertical
                            	vsWindow.Zoom = 1#

                            Comment

                            • joemo2003
                              New Member
                              • Feb 2007
                              • 142

                              #15
                              Originally posted by SammyB
                              Sorry, no Visio here, I'll try tonight. The only thing that I have used is what worked for you, Set vsPage=vsDoc.Pa ges(1). Maybe when you open the document, there is no active page, but that seems strange. From Help: "The ActivePage property returns a Page object only when the active window displays a drawing page; otherwise, it returns Nothing. To verify that a page is active, use the Is operator to compare the ActivePage property with Nothing."

                              So, you probably want (not tested)
                              Code:
                              	If vsApp.ActivePage Is Nothing Then
                              		Set vsPage = vsDoc.Pages(1)
                              	Else
                              		Set vsPage = vsApp.ActivePage
                              	End If
                              Here's some other code that worked for me that may help you.
                              Code:
                              	Dim vsApp As Visio.Application
                              	Dim vsDoc As Visio.Document
                              	Dim vsPage As Visio.Page
                              	Dim vsWindow As Visio.Window
                              	Set vsApp = CreateObject("Visio.Application")
                              	Set vsDoc = vsApp.Documents.Add("basic shapes.vss")
                              	Set vsPage = vsDoc.Pages(1)
                              	Set vsWindow = vsPage.OpenDrawWindow
                              	vsApp.Windows.Arrange visArrangeTileVertical
                              	vsWindow.Zoom = 1#

                              Yeah, it is working now. thanks

                              Comment

                              Working...