473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

If xapplication is open, Then

142 100+
How to defind the if function in excel vba: if xxapplication is open, then...?
Apr 6 '07 #1
13 2079
SammyB
807 Expert 512MB
How to defind the if function in excel vba: if xxapplication is open, then...?
You use GetObject. In your case,
Expand|Select|Wrap|Line Numbers
  1. Sub IsOpen()
  2.     Dim vsApp As Visio.Application
  3.     On Error Resume Next
  4.     Set vsApp = GetObject(, "Visio.Application")
  5.     If vsApp Is Nothing Then
  6.         MsgBox "Not Open"
  7.     Else
  8.         MsgBox "Open"
  9.     End If
  10. End Sub
Apr 6 '07 #2
joemo2003
142 100+
You use GetObject. In your case,
Expand|Select|Wrap|Line Numbers
  1. Sub IsOpen()
  2.     Dim vsApp As Visio.Application
  3.     On Error Resume Next
  4.     Set vsApp = GetObject(, "Visio.Application")
  5.     If vsApp Is Nothing Then
  6.         MsgBox "Not Open"
  7.     Else
  8.         MsgBox "Open"
  9.     End If
  10. End Sub
yes, that is what i am looking for.
thanks
Apr 6 '07 #3
joemo2003
142 100+
Sam,
got another question, since I open the visio within excel, and I set the "vsApp.Visible=False". I use "vsApp.quit" after "SaveAsEx", but sometime I doesn't do the "SaveAsEx" command and close the excel, so that visio still open and can see in the Task Manager. therefore, how to make it if the excel closed, the visio also will closed.

thanks
Apr 6 '07 #4
SammyB
807 Expert 512MB
Sam,
got another question, since I open the visio within excel, and I set the "vsApp.Visible=False". I use "vsApp.quit" after "SaveAsEx", but sometime I doesn't do the "SaveAsEx" command and close the excel, so that visio still open and can see in the Task Manager. therefore, how to make it if the excel closed, the visio also will closed.

thanks
You just need to add a Workbook Close event:
  1. In the Excel IDE, double click on ThisWorkbook in the project explorer to open the code for the workbook.
  2. Unless you have defined an event, he code window will be blank. Enter "Option Explicit" as the the first line. (BTW, you should do this in every code module. It forces you to define everything, thus keeping from spelling a variable two different ways.)
  3. At the top of the code window: On the left, click the drop-down and choose Workbook. On the right, click the drop-down and choose BeforeClose. Remove the Open event outline.
  4. In the module where you define vsApp, make sure it is public:
    Public vsApp As Visio.Application
  5. Find all of the places that you do vsApp.Quit and make sure that the next line is:
    Set vsApp = Nothing
  6. Make your Close event look like:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  3.     If Not vsApp Is Nothing Then vsApp.Close
  4. End Sub
Does that make sense?
Apr 6 '07 #5
SammyB
807 Expert 512MB
> "vsApp.Visible=False"
BTW, I find that it is the best policy to make any application that I use visible. It's just too easy to leave a hidden application running. Plus, it makes the users think that more is happening! ;)
Apr 6 '07 #6
joemo2003
142 100+
> "vsApp.Visible=False"
BTW, I find that it is the best policy to make any application that I use visible. It's just too easy to leave a hidden application running. Plus, it makes the users think that more is happening! ;)
thanks, I try it at monday.
Apr 8 '07 #7
joemo2003
142 100+
sam,
It doesn't work.
My code is in sheet I, so I use Option Explicit and Public vsApp as Visio.Application in sheet I under Microsoft Excel Objects. And under ThisWorkbook, I use
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Public vsApp As Visio.Application
  3. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  4.     If Not vsApp Is Nothing Then vsApp.Close
  5. End Sub
  6.  
but after I open the visio as not visible, and then close the excel, it said the vsApp is not defined.
Apr 9 '07 #8
SammyB
807 Expert 512MB
sam,
It doesn't work.
My code is in sheet I, so I use Option Explicit and Public vsApp as Visio.Application in sheet I under Microsoft Excel Objects. And under ThisWorkbook, I use
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Public vsApp As Visio.Application
  3. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  4. If Not vsApp Is Nothing Then vsApp.Close
  5. End Sub
  6.  
but after I open the visio as not visible, and then close the excel, it said the vsApp is not defined.
You cannot have vsApp defined in two different places. Define it as Public in Sheet1; remove the definition in ThisWorkbook.
Apr 10 '07 #9
joemo2003
142 100+
You cannot have vsApp defined in two different places. Define it as Public in Sheet1; remove the definition in ThisWorkbook.
I try that too, if I only define it as public in Sheet1, then it have error vsApp not define when I close up the excel, that is why I try also define it on ThisWorkbook.
Apr 10 '07 #10
SammyB
807 Expert 512MB
I try that too, if I only define it as public in Sheet1, then it have error vsApp not define when I close up the excel, that is why I try also define it on ThisWorkbook.
Sorry, I wrote that when I didn't have Visio. It should be vsApp.Quit. Also, in some versions of Excel, you cannot have Public variables in sheet code, so it may be best to put the "Public vsApp as Visio.Application" in a code (macro) module.
Apr 10 '07 #11
joemo2003
142 100+
Sorry, I wrote that when I didn't have Visio. It should be vsApp.Quit. Also, in some versions of Excel, you cannot have Public variables in sheet code, so it may be best to put the "Public vsApp as Visio.Application" in a code (macro) module.
How can i transfer my code from Sheet 1 to module, i try to copy and paste or export and import, but it lose the link to the button in sheet1.
Apr 10 '07 #12
SammyB
807 Expert 512MB
How can i transfer my code from Sheet 1 to module, i try to copy and paste or export and import, but it lose the link to the button in sheet1.
Don't move any code! Just move the one line Public vsApp as ...
In other words:
ThisDocument -- document event code
Sheet1 -- button event code
Module1 -- global definition of vsApp
Apr 10 '07 #13
joemo2003
142 100+
Don't move any code! Just move the one line Public vsApp as ...
In other words:
ThisDocument -- document event code
Sheet1 -- button event code
Module1 -- global definition of vsApp
yeah, that work. thanks
Apr 10 '07 #14

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

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
18
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page...
6
by: Curt Emich | last post by:
I get the following error when I write any code against a connection that is hooked to an Access database: The Microsoft Jet database engine cannot open the file...
29
by: wayne | last post by:
Hey there... I'm having some problems passing url parameters with an open.window command. I'm not terribly familiar with java script but here is the code below. When executed it opens the...
115
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i...
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
4
by: John | last post by:
Hi, I generate a report in a comma delimited file and give it a name like MyReport.csv . I then set a Hyperlink control to point tp the file HyperLink1.text = "Download"...
2
by: Jonathan Trevor | last post by:
Hi, For the last couple of releases of a product we're developing we've been running to very wierd behavior from IE and our ASP.NET web application which serves up various types of files and I'm...
6
by: Mike | last post by:
We are intermitantly receiving this error on our website. ExecuteReader requires an open and available Connection. The connection's current state is connecting. Following is the code from the Load...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.