I use a program that imports into Excel that requires that the workbook is
closed prior to the import.
How do you check to see if an Excel workbook is open, and then close the
workbook?
How do you then look to see if Excel is still running and then close it
(Excel.exe)?
I already know how to open an instance of Excel, use it, and then close it,
but I have not figured out how to check for an already open instance of a
workbook and/or Excel.
Thanks,
--
Randy 8 4871
On Mon, 22 Aug 2005 04:52:11 -0700, "Randy Wayne" <ra********@discussions.microsoft.com> wrote:
¤ I use a program that imports into Excel that requires that the workbook is
¤ closed prior to the import.
¤
¤ How do you check to see if an Excel workbook is open, and then close the
¤ workbook?
¤
¤ How do you then look to see if Excel is still running and then close it
¤ (Excel.exe)?
¤
¤ I already know how to open an instance of Excel, use it, and then close it,
¤ but I have not figured out how to check for an already open instance of a
¤ workbook and/or Excel.
You can use API function calls to do this reliably. You can also use the second argument in
FindWindow, which is the window (title) name.
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg
As Int32, _
ByVal wParam As Int32, ByVal
lParam As Int32) As Int32
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As
String, _
ByVal lpDirectory As
String, _
ByVal lpResult As
System.Text.StringBuilder) As Int32
Public Function TerminateExcel()
Dim ClassName As String
Dim WindowHandle As Int32
Dim ReturnVal As Int32
Const WM_QUIT = &H12
Do
ClassName = "XLMain"
WindowHandle = FindWindow(ClassName, Nothing)
If WindowHandle Then
ReturnVal = PostMessage(WindowHandle, WM_QUIT, 0, 0)
End If
Loop Until WindowHandle = 0
End Function
Paul
~~~~
Microsoft MVP (Visual Basic)
Paul:
Thanks for the reply.
Visual Studio states that I need to declare "FindWindow". What variable
type is it?
--
Thanks,
Randy
"Paul Clement" wrote: On Mon, 22 Aug 2005 04:52:11 -0700, "Randy Wayne" <ra********@discussions.microsoft.com> wrote:
¤ I use a program that imports into Excel that requires that the workbook is ¤ closed prior to the import. ¤ ¤ How do you check to see if an Excel workbook is open, and then close the ¤ workbook? ¤ ¤ How do you then look to see if Excel is still running and then close it ¤ (Excel.exe)? ¤ ¤ I already know how to open an instance of Excel, use it, and then close it, ¤ but I have not figured out how to check for an already open instance of a ¤ workbook and/or Excel.
You can use API function calls to do this reliably. You can also use the second argument in FindWindow, which is the window (title) name.
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, _ ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, _ ByVal lpDirectory As String, _ ByVal lpResult As System.Text.StringBuilder) As Int32
Public Function TerminateExcel()
Dim ClassName As String Dim WindowHandle As Int32 Dim ReturnVal As Int32 Const WM_QUIT = &H12
Do
ClassName = "XLMain" WindowHandle = FindWindow(ClassName, Nothing)
If WindowHandle Then ReturnVal = PostMessage(WindowHandle, WM_QUIT, 0, 0) End If
Loop Until WindowHandle = 0
End Function
Paul ~~~~ Microsoft MVP (Visual Basic)
you should be able to use the diagnostics classes http://www.c-sharpcorner.com/1/protracker_csv1.asp
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Randy Wayne" <ra********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com... I use a program that imports into Excel that requires that the workbook is closed prior to the import.
How do you check to see if an Excel workbook is open, and then close the workbook?
How do you then look to see if Excel is still running and then close it (Excel.exe)?
I already know how to open an instance of Excel, use it, and then close it, but I have not figured out how to check for an already open instance of a workbook and/or Excel.
Thanks, --
Randy
John:
Thank you for the reply. I will look at that class as well as the link you
provided sometime today.
--
Thanks,
Randy
"John Timney (ASP.NET MVP)" wrote: you should be able to use the diagnostics classes
http://www.c-sharpcorner.com/1/protracker_csv1.asp
-- Regards
John Timney ASP.NET MVP Microsoft Regional Director
"Randy Wayne" <ra********@discussions.microsoft.com> wrote in message news:38**********************************@microsof t.com...I use a program that imports into Excel that requires that the workbook is closed prior to the import.
How do you check to see if an Excel workbook is open, and then close the workbook?
How do you then look to see if Excel is still running and then close it (Excel.exe)?
I already know how to open an instance of Excel, use it, and then close it, but I have not figured out how to check for an already open instance of a workbook and/or Excel.
Thanks, --
Randy
On Mon, 22 Aug 2005 12:50:02 -0700, "Randy Wayne" <ra********@discussions.microsoft.com> wrote:
¤ Paul:
¤
¤ Thanks for the reply.
¤
¤ Visual Studio states that I need to declare "FindWindow". What variable
¤ type is it?
FindWindow is an API function call. It should be declared at the top of the code module. The declare
is in the code I posted.
Paul
~~~~
Microsoft MVP (Visual Basic)
Paul:
Again I thank you for the reply.
Please forgive my ingorance, but I have looked and looked for a Declaration
for "FindWindow". I have copied back the two Declare statements from your
first post.
What am I missing?
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd
As Int32, _
ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As
Int32
Declare Function FindExecutable Lib "shell32.dll" Alias
"FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, _
ByVal lpResult As System.Text.StringBuilder) As Int32
--
Thanks,
Randy
"Paul Clement" wrote: On Mon, 22 Aug 2005 12:50:02 -0700, "Randy Wayne" <ra********@discussions.microsoft.com> wrote:
¤ Paul: ¤ ¤ Thanks for the reply. ¤ ¤ Visual Studio states that I need to declare "FindWindow". What variable ¤ type is it?
FindWindow is an API function call. It should be declared at the top of the code module. The declare is in the code I posted.
Paul ~~~~ Microsoft MVP (Visual Basic)
On Tue, 23 Aug 2005 11:46:44 -0700, "Randy Wayne" <ra********@discussions.microsoft.com> wrote:
¤ Paul:
¤
¤ Again I thank you for the reply.
¤
¤ Please forgive my ingorance, but I have looked and looked for a Declaration
¤ for "FindWindow". I have copied back the two Declare statements from your
¤ first post.
¤
¤ What am I missing?
¤
¤ Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd
¤ As Int32, _
¤ ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As
¤ Int32
¤
¤ Declare Function FindExecutable Lib "shell32.dll" Alias
¤ "FindExecutableA" _
¤ (ByVal lpFile As String, ByVal lpDirectory As String, _
¤ ByVal lpResult As System.Text.StringBuilder) As Int32
Sorry, my bad. I posted the incorrect API declare. Below is FindWindow:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Int32
Paul
~~~~
Microsoft MVP (Visual Basic)
Paul:
Fantastic!!
Thank you for sticking with this for me.
Randy
"Paul Clement" wrote: On Tue, 23 Aug 2005 11:46:44 -0700, "Randy Wayne" <ra********@discussions.microsoft.com> wrote:
¤ Paul: ¤ ¤ Again I thank you for the reply. ¤ ¤ Please forgive my ingorance, but I have looked and looked for a Declaration ¤ for "FindWindow". I have copied back the two Declare statements from your ¤ first post. ¤ ¤ What am I missing? ¤ ¤ Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd ¤ As Int32, _ ¤ ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As ¤ Int32 ¤ ¤ Declare Function FindExecutable Lib "shell32.dll" Alias ¤ "FindExecutableA" _ ¤ (ByVal lpFile As String, ByVal lpDirectory As String, _ ¤ ByVal lpResult As System.Text.StringBuilder) As Int32
Sorry, my bad. I posted the incorrect API declare. Below is FindWindow:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32 Paul ~~~~ Microsoft MVP (Visual Basic) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Otie |
last post by:
I found the following under the GetObject help notes and in the
example for GetObject:
"This example uses the GetObject function to get a reference to a
specific Microsoft Excel worksheet...
|
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...
|
by: Gary Cobden |
last post by:
Hi
I have a routine that uses VBA to open a hidden occurence of Excel,
and do background computations.
However, in the event that the routine terminates abnormally, I have
not been able to...
|
by: Wenke Ji |
last post by:
Hi
I open a Excel workbook using below API:
Set ExcelServer = CreateObject("EXCEL.Application")
Set TargetWorkbook = ExcelServer.Workbooks.Open
(CurrentBook)
Befor the programm exit , I use...
|
by: LP |
last post by:
Hello,
I am trying to use .NET with Excel. I installed Office 2003 and selected
..NET programming suport option, so it installed all those PIA, as MS
sugests. But I can not find a way to destroy...
|
by: Randy Wayne |
last post by:
I use a program that imports into Excel that requires that the workbook is
closed prior to the import.
How do you check to see if an Excel workbook is open, and then close the
workbook?
How...
|
by: mabond |
last post by:
Hi
recently read a posting and reply about Excel processs still running after
the Appliction.Quit was called. Thought I might be able to use the same...
|
by: alexia.bee |
last post by:
Hi all,
In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.
here is a snipcode
public...
|
by: hakkatil |
last post by:
Hi to all,
I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |