Instance of Word staying open after saving OLE object

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I'm using this to extract an OLE object, (Word document), from a worksheet;

Code:
Dim wsActive As Worksheet
Dim ws As Worksheet
Dim oOleObj As OLEObject
Dim oDoc As Object
Dim DestFolder As String
Dim sDocType As String
Dim lCnt As Long


If ActiveWorkbook Is Nothing Then Exit Sub
Application.ScreenUpdating = False
DestFolder = ThisWorkbook.Path & "\Sgt Toolbox Files DO NOT DELETE"
Set wsActive = ActiveSheet
lCnt = 0
Sheets("Handover Setup").Activate
Set ws = Sheets("Handover Setup")
For Each oOleObj In ws.OLEObjects
If oOleObj.OLEType = xlOLEEmbed Then
sDocType = oOleObj.progID
sDocType = Left(sDocType, InStr(sDocType, ".") - 1)
If sDocType = "Word" Then
oOleObj.Select
oOleObj.Verb xlVerbPrimary
Set oDoc = oOleObj.Object
oDoc.SaveAs FileName:=DestFolder & "\Blank Handover File.docx", FileFormat:=wdFormatXMLDocumentMacroEnabled
oDoc.Close savechanges:=False
lCnt = lCnt + 1
End If
End If
Next oOleObj
ActiveWindow.WindowState = xlMaximized
Sheet4.Activate
Application.ScreenUpdating = True

It works fine, except afterwards it leaves an instance of Word open, not an actual document, just the blank blue screen. Can someone show me how to close it please? Also, if possible, I would need it to account for any existing documents that are open, in other words leave any open word documents as they are and only close this 'blank' instance.
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Re: Instance of Word staying open after saving OEL object

Exiting OLE Apps has always been problematic. After:
Next oOleObj
try inserting:
oOleObj.Application.Quit
 
Upvote 0
Re: Instance of Word staying open after saving OEL object

Seems to work - thanks Paul!
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,156
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top