If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Closing Excel with Visual Basic

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 01-22-04, 11:27
Craig Silberman Craig Silberman is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
Thank you

Dianeb;

Thank you. That solved my problem. Whew. Much appreciated.

Craig
Reply With Quote
  #17 (permalink)  
Old 03-26-04, 14:54
sacase sacase is offline
Registered User
 
Join Date: Mar 2004
Location: Jacksonville, FL
Posts: 1
Closing Excel

I was having the same problem and solved it by adding the following lines of code to get the window handle and then activate it and after I saved the workbook I sent the WM_CLOSE message:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Dim WinHandle As Long
Dim curApp As Excel.Application

Do While (FindWindow("XLMain", vbNullString)) <> 0
WinHandle = FindWindow("XLMain", vbNullString)
ShowWindow WinWnd1, SW_SHOWNORMAL

Set curApp = GetObject(, "Excel.Application")
curApp.ActiveWorkbook.SaveAs "C:\backup\Excel" & i & "_"
i = i + 1

SendMessage WinHandle, WM_CLOSE, 0, 0

Set curApp = Nothing

Loop

Let me know if this helps.

Steve
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On