PDA

View Full Version : ActiveDocument.Close error



IonutC
04-20-2016, 12:42 AM
Hi guys,

I have a code and it works perfectly, but because I use a template dotx I have an error when I am trying to close the document.
In the excel appears a window to save the doc somewhere as dotm but i don;t want to do that. I simply need to close my active doc without saving anything etc.

Can you please advise?



Sub LateBinding_PDF()


Dim wdApp As Object

Dim SaveName As String
Dim FileExt As String
Dim Name As String
Dim i As Long
Dim Lr As Long
Dim MyPath As String
Dim MyFile As String


Application.CutCopyMode = False
Application.ScreenUpdating = False
Set wdApp = CreateObject("Word.Application")

Worksheets("Sheet1").Activate
MyPath = Environ("UserProfile")
' MyFile = "test.dotx"
MyFile = "test.dotm"
Lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To Lr
Worksheets("Sheet1").Activate
With wdApp
.Visible = True
.Activate
.Documents.Add MyPath & "\Desktop\MacroFiles\" & MyFile
.ActiveDocument.Bookmarks("DataRaport").Range.Text = Date
.ActiveDocument.Bookmarks("OverallCaseID").Range.Text = Cells(i, 8).Value
.ActiveDocument.Bookmarks("WWCaseID").Range.Text = Cells(i, 4).Value
.ActiveDocument.Bookmarks("NameOfSearchSubject").Range.Text = Cells(i, 9).Value

FileExt = ".pdf"

SaveName = Environ("Userprofile") & "\Desktop\MacroFiles\Report" & " " & _
Format(Now, "yyyy-mm-dd hh-mm-ss") & FileExt


.ActiveDocument.ExportAsFixedFormat OutputFileName:=SaveName, ExportFormat:=17



.ActiveDocument.Close , SaveChanges:=wdDoNotSaveChanges, OriginalFormat:=wdOriginalDocumentFormat

End With


Next i
wdApp.Quit
Set wdApp = Nothing
Application.CutCopyMode = True
Application.ScreenUpdating = True
End Sub



Maybe I need to put numbers instead of wdDoNotSaveChanges and wdOriginalDocumentFormat.
I searched on MSN and I was not able to find the real numbers for them.

Thank you in advance,
Ionut

Aflatoon
04-20-2016, 03:42 AM
Cross-posted and answered here: http://www.mrexcel.com/forum/excel-questions/935979-activedocument-close-error.html