Instance of Word staying open after saving OLE object

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,421
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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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