PC Review


Reply
Thread Tools Rate Thread

Closing WINWORD.EXE from Excel VBA when my main proc ends

 
 
=?Utf-8?B?RWRtdW5k?=
Guest
Posts: n/a
 
      22nd Aug 2007
My main proc in Excel calls the below sample sub proc (which uses Word VBA),
each time main proc runs. However, I realize Windows Task Manager seem to
display many instances of "WINWORD.EXE" even after I close & exit Excel
Application. How can I close "WINWORD.EXE" each time sub proc ends?

Sub MainProc()

Call SaveACopyToLocal_Fix_CRLF_UNIX_Bug(iFN:=iPath & "\" & iFN_isbp004,
iReadOnly:=True, iFormat:=0, iEncoding:=1252, oFN:=oPath & "\" & oFN_isbp004,
oFileFormat:=2, oAddToRecentFiles:=True, oEncoding:=437, oLineEnding:=0)

End Sub


Private Sub SaveACopyToLocal_Fix_CRLF_UNIX_Bug(iFN As String, iReadOnly As
Boolean, iFormat As Integer, iEncoding As Integer, oFN As String, oFileFormat
As Integer, oAddToRecentFiles As Boolean, oEncoding As Integer, oLineEnding
As Integer)
Dim WordApp As Object

Set WordApp = CreateObject("Word.Application")
On Error GoTo ErrorHandler:
With WordApp
.Documents.Open Filename:=iFN, ReadOnly:=iReadOnly, Format:=iFormat,
Encoding:=iEncoding
.ActiveDocument.SaveAs Filename:=oFN, FileFormat:=oFileFormat,
AddToRecentFiles:=oAddToRecentFiles, Encoding:=oEncoding,
LineEnding:=oLineEnding
.Documents(oFN).Close False
End With
Set WordApp = Nothing
Exit Sub

ErrorHandler:
Msg = "Please ensure that you are properly connected to the server " &
vbCrLf
Msg = Msg & "before attemting to rerun this application. "
MsgBox Msg, vbCritical, APPNAME & " (UNABLE TO CONTACT SERVER)"

End Sub

Thanks

--
Edmund
(Using Excel 2003)
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWRtdW5k?=
Guest
Posts: n/a
 
      22nd Aug 2007
Forgot to specify that the many instances of "WINWORD.EXE" which appears in
Windows Task Manager are found in tabname "Processees" instead of tab name
"Application".

--
Edmund
(Using Excel XP)

 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      22nd Aug 2007

WordApp.Quit
Set WordApp = Nothing
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Edmund" wrote in message
My main proc in Excel calls the below sample sub proc (which uses Word VBA),
each time main proc runs. However, I realize Windows Task Manager seem to
display many instances of "WINWORD.EXE" even after I close & exit Excel
Application. How can I close "WINWORD.EXE" each time sub proc ends?

Sub MainProc()
Call SaveACopyToLocal_Fix_CRLF_UNIX_Bug(iFN:=iPath & "\" & iFN_isbp004,
iReadOnly:=True, iFormat:=0, iEncoding:=1252, oFN:=oPath & "\" & oFN_isbp004,
oFileFormat:=2, oAddToRecentFiles:=True, oEncoding:=437, oLineEnding:=0)
End Sub


Private Sub SaveACopyToLocal_Fix_CRLF_UNIX_Bug(iFN As String, iReadOnly As
Boolean, iFormat As Integer, iEncoding As Integer, oFN As String, oFileFormat
As Integer, oAddToRecentFiles As Boolean, oEncoding As Integer, oLineEnding
As Integer)
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
On Error GoTo ErrorHandler:
With WordApp
.Documents.Open Filename:=iFN, ReadOnly:=iReadOnly, Format:=iFormat,
Encoding:=iEncoding
.ActiveDocument.SaveAs Filename:=oFN, FileFormat:=oFileFormat,
AddToRecentFiles:=oAddToRecentFiles, Encoding:=oEncoding,
LineEnding:=oLineEnding
.Documents(oFN).Close False
End With
Set WordApp = Nothing
Exit Sub
ErrorHandler:
Msg = "Please ensure that you are properly connected to the server " &
vbCrLf
Msg = Msg & "before attemting to rerun this application. "
MsgBox Msg, vbCritical, APPNAME & " (UNABLE TO CONTACT SERVER)"
End Sub
Thanks
--
Edmund
(Using Excel 2003)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
winword.exe process does not end after closing document on the net tewill Microsoft Word Document Management 3 25th Oct 2009 06:01 AM
Sub Main Ends so does the application rrowe Microsoft VB .NET 6 25th Jul 2006 02:25 PM
app ends after sub main() =?Utf-8?B?QmVu?= Microsoft VB .NET 4 26th Jul 2005 05:06 PM
WinWord self closing glitch. =?Utf-8?B?VGFjb0JvYg==?= Microsoft Word Document Management 1 24th Nov 2004 03:56 PM
Closing winword.exe in Code CMAnderso Microsoft Access Form Coding 2 19th Dec 2003 05:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:50 AM.