sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,421
- Office Version
- 2016
- Platform
- Windows
I'm using this to extract a Word OLE document, write to it, then save it as a pdf document;
It's a bit of a mess because I've been playing around with different bits of code I've found on here.
It works OK, but the issue I'm having is that is leaves an instance of Word open. I need it to close that instance of Word but leave any others open, (ones that may be open when this is run).
Code:
'Extract File
If ActiveWorkbook Is Nothing Then Exit Sub
Application.ScreenUpdating = False
DestFolder = ThisWorkbook.Path & "\Toolbox Files\121 Files"
Set wsActive = ActiveSheet
lCnt = 0
Sheets("Setup").Activate
Set ws = Sheets("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.Bookmarks("Staff").Range.InsertAfter NewMeetingFrm.Combobox1.Value
oDoc.Bookmarks("Manager").Range.InsertAfter NewMeetingFrm.TextBox2.Value
oDoc.Bookmarks("MeetingDate").Range.InsertAfter Format(NewMeetingFrm.TextBox3, "dd mmmm yyyy")
oDoc.Bookmarks("Welfare").Range.InsertAfter NewMeetingFrm.txtwelfare.Value
oDoc.Bookmarks("PDR").Range.InsertAfter NewMeetingFrm.txtpdr.Value
oDoc.Bookmarks("Performance").Range.InsertAfter NewMeetingFrm.txtperformance.Value
oDoc.Bookmarks("Competencies").Range.InsertAfter NewMeetingFrm.txtcompetencies.Value
oDoc.Bookmarks("SelfInspection").Range.InsertAfter NewMeetingFrm.txtinspection.Value
oDoc.Bookmarks("PDRS").Range.InsertAfter NewMeetingFrm.txtsupervision.Value
oDoc.Bookmarks("Attendance").Range.InsertAfter NewMeetingFrm.txtattendance.Value
oDoc.Bookmarks("Career").Range.InsertAfter NewMeetingFrm.txtcareer.Value
oDoc.Bookmarks("Project").Range.InsertAfter NewMeetingFrm.txtproject.Value
oDoc.Bookmarks("Comments").Range.InsertAfter NewMeetingFrm.txtcomments.Value
oDoc.Bookmarks("Date").Range.InsertAfter Format(now, "dd mmmm yyyy")
oDoc.Bookmarks("Date2").Range.InsertAfter Format(now, "dd mmmm yyyy")
dt = Format(NewMeetingFrm.TextBox3, "dd_mmmm_yyyy")
strFile = "1-2-1 Meeting Record - " & dt & ".pdf"
oDoc.SaveAs ThisWorkbook.Path & "\Toolbox Files\121 Files\" & strFile, FileFormat:=17
oDoc.Close savechanges:=False
lCnt = lCnt + 1
End If
End If
Next oOleObj
ActiveWindow.WindowState = xlMaximized
It's a bit of a mess because I've been playing around with different bits of code I've found on here.
It works OK, but the issue I'm having is that is leaves an instance of Word open. I need it to close that instance of Word but leave any others open, (ones that may be open when this is run).