By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

open visio in Excel

100+
P: 142
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.Application
Set objVisio = New Visio.Application
objVisio.Visible = True
Dim vFile As Variant
vFile = objVisio.Documents.Open("All Visio Files (*.vs*; *.v?x)")
If vFile <> False Then
Dim vsobj As Visio.Document
Set vsobj = objVisio.Documents.Add(vFile)
End If
End Sub

Second way:

Private Sub button1_click()
Dim objVisio As Visio.Application
Set objVisio = New Visio.Application
objVisio.Visible = True
Dim uiObj As Visio.UIObject
Set uiObj = objVisio.BuiltInToolbars(0)
End Sub
Mar 16 '07 #1
Share this Question
Share on Google+
14 Replies


100+
P: 142
I mean both way not work.
Mar 17 '07 #2

100+
P: 142
I mean both way not work.
someone help
Mar 19 '07 #3

SammyB
Expert 100+
P: 807
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.GetOpenFileName instead of objVisio.Documents.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
Mar 19 '07 #4

100+
P: 142
Your first way looks almost correct, but you want to use Excel's Application.GetOpenFileName instead of objVisio.Documents.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.
Mar 19 '07 #5

SammyB
Expert 100+
P: 807
I try GetOpenFileName before, GetOpenFileName not support visio.
GetOpenFileName is an Excel interface to get a FileName. If you are running Excel, then Application.GetOpenFileName 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.
Mar 19 '07 #6

100+
P: 142
GetOpenFileName is an Excel interface to get a FileName. If you are running Excel, then Application.GetOpenFileName 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.Application
Set objVisio = New Visio.Application
objVisio.Visible = True
Dim vFile As Variant
vFile = objVisio.GetOpenFileName("All Visio Files (*.vs*; *.v?x)")
If vFile <> False Then
Dim vsobj As Visio.Document
Set vsobj = objVisio.Documents.Add(vFile)
End If
End Sub
Mar 19 '07 #7

SammyB
Expert 100+
P: 807
GetOpenFileName is an EXCEL object. Use Application.GetOpenFileName(...)
Mar 19 '07 #8

100+
P: 142
GetOpenFileName is an EXCEL object. Use Application.GetOpenFileName(...)
I tried:
vFile = objVisio.Application.GetOpenFileName("All Visio Files (*.vs*; *.v?x)")
vFile = objVisio.visio.GetOpenFileName("All Visio Files (*.vs*; *.v?x)")
vFile = Application.GetOpenFileName("All Visio Files (*.vs*; *.v?x)")
vFile = Visio.GetOpenFileName("All Visio Files (*.vs*; *.v?x)")

They all said Object don't support this property or method.
Mar 19 '07 #9

SammyB
Expert 100+
P: 807
Third one is close, but should be
Expand|Select|Wrap|Line Numbers
  1. vFile = Application.GetOpenFilename("All Visio Files (*.vs*;*.v?x), *.vs*;*.v?x")
Mar 19 '07 #10

100+
P: 142
Third one is close, but should be
Expand|Select|Wrap|Line Numbers
  1. vFile = Application.GetOpenFilename("All Visio Files (*.vs*;*.v?x), *.vs*;*.v?x")
Yeah, it do work. thanks
Mar 19 '07 #11

SammyB
Expert 100+
P: 807
Fantastic! (_)/
Mar 19 '07 #12

100+
P: 142
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.Pages(1)
but what i want is input text to the active page, so i try:
Set vsPage=vsDoc.activepage
Set vsPage=vsApp.vsDoc.activepage
Set vsPage=vsApp.activepage
Set vsPage=vsApp.activewindow.activepage
However, they all are not working, do u know what is wrong?

Thanks
Mar 20 '07 #13

SammyB
Expert 100+
P: 807
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.Pages(1)
but what i want is input text to the active page, so i try:
Set vsPage=vsDoc.activepage
Set vsPage=vsApp.vsDoc.activepage
Set vsPage=vsApp.activepage
Set vsPage=vsApp.activewindow.activepage
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.Pages(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)
Expand|Select|Wrap|Line Numbers
  1.     If vsApp.ActivePage Is Nothing Then
  2.         Set vsPage = vsDoc.Pages(1)
  3.     Else
  4.         Set vsPage = vsApp.ActivePage
  5.     End If
Here's some other code that worked for me that may help you.
Expand|Select|Wrap|Line Numbers
  1.     Dim vsApp As Visio.Application
  2.     Dim vsDoc As Visio.Document
  3.     Dim vsPage As Visio.Page
  4.     Dim vsWindow As Visio.Window
  5.     Set vsApp = CreateObject("Visio.Application")
  6.     Set vsDoc = vsApp.Documents.Add("basic shapes.vss")
  7.     Set vsPage = vsDoc.Pages(1)
  8.     Set vsWindow = vsPage.OpenDrawWindow
  9.     vsApp.Windows.Arrange visArrangeTileVertical
  10.     vsWindow.Zoom = 1#
Mar 20 '07 #14

100+
P: 142
Sorry, no Visio here, I'll try tonight. The only thing that I have used is what worked for you, Set vsPage=vsDoc.Pages(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)
Expand|Select|Wrap|Line Numbers
  1.     If vsApp.ActivePage Is Nothing Then
  2.         Set vsPage = vsDoc.Pages(1)
  3.     Else
  4.         Set vsPage = vsApp.ActivePage
  5.     End If
Here's some other code that worked for me that may help you.
Expand|Select|Wrap|Line Numbers
  1.     Dim vsApp As Visio.Application
  2.     Dim vsDoc As Visio.Document
  3.     Dim vsPage As Visio.Page
  4.     Dim vsWindow As Visio.Window
  5.     Set vsApp = CreateObject("Visio.Application")
  6.     Set vsDoc = vsApp.Documents.Add("basic shapes.vss")
  7.     Set vsPage = vsDoc.Pages(1)
  8.     Set vsWindow = vsPage.OpenDrawWindow
  9.     vsApp.Windows.Arrange visArrangeTileVertical
  10.     vsWindow.Zoom = 1#

Yeah, it is working now. thanks
Mar 20 '07 #15

Post your reply

Sign in to post your reply or Sign up for a free account.