sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I'm using this to extract an OLE object, (Word document), from a worksheet;
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.
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: