473,396 Members | 1,784 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,396 software developers and data experts.

Detecting existing Excel instance the .Net way?

In VB6, I would check to see if Excel was already running by this technique

Private m_booExcelCreatedHere As Boolean

Dim xlApp as Excel.Application

On Error Resume Next ' temporarily suppress error handler
Set xlApp = GetObject(,"Excel.Application")
On Error GoTo PROC_ERR ' resume normal error handling
If xlApp Is Nothing Then
Set xlApp = New Excel.Application
' xlApp.Visible = True ' uncomment when debugging to see what's
happening
m_booExcelCreatedHere = True
Else
m_booExcelCreatedHere = False
End If

Later on, I'd use m_booExcelCreatedHere to determine if I should leave Excel
running (perhaps because the user had started it themselves and is working
with other workbooks unrelated to mine) or use xlApp.Quit and set xlApp to
Nothing.

What's the VB.Net way of doing this?
Nov 20 '05 #1
1 8317
Hi,

If Process.GetProcessesByName("excel").GetLength(0) > 0 Then

MessageBox.Show("Excel is running")

Else

MessageBox.Show("Not running")

End If

Ken

----------------------------

"Fred Morrison" <fm*******@erols.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
In VB6, I would check to see if Excel was already running by this technique
Private m_booExcelCreatedHere As Boolean

Dim xlApp as Excel.Application

On Error Resume Next ' temporarily suppress error handler
Set xlApp = GetObject(,"Excel.Application")
On Error GoTo PROC_ERR ' resume normal error handling
If xlApp Is Nothing Then
Set xlApp = New Excel.Application
' xlApp.Visible = True ' uncomment when debugging to see what's
happening
m_booExcelCreatedHere = True
Else
m_booExcelCreatedHere = False
End If

Later on, I'd use m_booExcelCreatedHere to determine if I should leave Excel running (perhaps because the user had started it themselves and is working
with other workbooks unrelated to mine) or use xlApp.Quit and set xlApp to
Nothing.

What's the VB.Net way of doing this?

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
2
by: Anne Sachleben via AccessMonster.com | last post by:
I am using the TransferSpreadsheet function to export a query result to a specific worksheet in an Excel file titled "report". I want the result to be exported to the worksheet titled "facts". ...
2
by: Adine | last post by:
User has opened an excel file and I want to take the control of the file. In VB6 was not hard. Just I needed to use "GetObject" then I could select the workbook. But now I don't know how to do it...
4
by: Josh Behl | last post by:
When I try to programmatically open an existing Excel document using a custom windows form, it works perfectly. I instanciate a new instance of the Excel.ApplicationClass and then set the Visible...
2
by: leeedw | last post by:
Hi everyone, I use the following code whenever I export to Excel from VB.NET objExcel = New Excel.Application() objWorkBooks = objExcel.Workbooks objWorkBook = objWorkBooks.Add objWorkSheet...
3
by: Ian Dunn | last post by:
I'm simply trying to access an instance of Excel that has been opened manually by the user in order to put a few values in the existing sheet. Here's the code I've tried: Dim oXL As...
4
by: Marco Aschwanden | last post by:
Hi I would like to 1. import an existing Excel-sheet (a template) 2. and add some data to it 3. and save it under a different name afterwards. To me it seems, that pyExcelerator does not...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
1
by: popsoftheyear | last post by:
I'm trying to automate some very simple things in excel, but have run into a roadblock (using c++). To detect excel closing, I just monitor the Excel Process using WaitForSingleObject. In order to...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.