How to defind the if function in excel vba: if xxapplication is open, then...?
13 2079
How to defind the if function in excel vba: if xxapplication is open, then...?
You use GetObject. In your case, - Sub IsOpen()
-
Dim vsApp As Visio.Application
-
On Error Resume Next
-
Set vsApp = GetObject(, "Visio.Application")
-
If vsApp Is Nothing Then
-
MsgBox "Not Open"
-
Else
-
MsgBox "Open"
-
End If
-
End Sub
You use GetObject. In your case, - Sub IsOpen()
-
Dim vsApp As Visio.Application
-
On Error Resume Next
-
Set vsApp = GetObject(, "Visio.Application")
-
If vsApp Is Nothing Then
-
MsgBox "Not Open"
-
Else
-
MsgBox "Open"
-
End If
-
End Sub
yes, that is what i am looking for.
thanks
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
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: - In the Excel IDE, double click on ThisWorkbook in the project explorer to open the code for the workbook.
- 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.)
- 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.
- In the module where you define vsApp, make sure it is public:
Public vsApp As Visio.Application - Find all of the places that you do vsApp.Quit and make sure that the next line is:
Set vsApp = Nothing - Make your Close event look like:
- Option Explicit
-
Private Sub Workbook_BeforeClose(Cancel As Boolean)
-
If Not vsApp Is Nothing Then vsApp.Close
-
End Sub
Does that make sense?
> "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! ;)
> "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.
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 -
Option Explicit
-
Public vsApp As Visio.Application
-
Private Sub Workbook_BeforeClose(Cancel As Boolean)
-
If Not vsApp Is Nothing Then vsApp.Close
-
End Sub
-
but after I open the visio as not visible, and then close the excel, it said the vsApp is not defined.
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 -
Option Explicit
-
Public vsApp As Visio.Application
-
Private Sub Workbook_BeforeClose(Cancel As Boolean)
-
If Not vsApp Is Nothing Then vsApp.Close
-
End Sub
-
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.
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.
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.
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.
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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...
| | |