#1
|
|||
|
|||
Macro-enabled Template
The below code works great, except for one thing. Once saved as a macro-enabled template, if you press cancel on the "save as" dialog box it errors with a "runtime error 4198...Command failed". It works great when it's a m-e doc
can someone tell me what I am missing? please advise & thank you Code:
Public Sub EmailForm_Click() Dim outl As Object Dim Mail As Object Dim Msg, Style, Title, Help, Ctxt, Response, MyString Dim PDFname As String Msg = "Choose where to save this form. An email with a .pdf attachment will automatically be generated" Style = vbOKCancel + vbQuestion + vbDefaultButton2 Title = "Confirm save & email" Ctxt = 1000 Response = MsgBox(Msg, Style, Title, Help, Ctxt) If Response = vbOK Then 'ActiveDocument.Save PDFname = ActiveDocument.Path & "\" & "SonicWall Config-" & AcctName & ".pdf" ActiveDocument.ExportAsFixedFormat OutputFileName:=PDFname, ExportFormat:=wdExportFormatPDF, _ OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _ Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, UseISO19005_1:=False, _ CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True Set outl = CreateObject("Outlook.Application") Set Mail = outl.CreateItem(0) Mail.Subject = "SonicWall Config Request- " & AcctName Mail.Body = "" Mail.Importance = olImportanceHigh Mail.To = "mtomlinson@tulsacash.com" Mail.Attachments.Add PDFname Mail.Display Else MsgBox "The document was saved, but will not be emailed" Cancel = True End If End Sub Last edited by macropod; 01-29-2013 at 09:47 PM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
Hi ReviTULize,
On which line does the error occur? When does the document get saved (the 'cancel' message suggests it does, but the code doesn't evidence that)?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks for the reply!!
It's happening on the "ActiveDocument.Save" line. If I omit the line it will not allow me to save it at all. I am basically looking for this to ask the user where to save the file, create a .pdf with the contents and save it in the same location, and email. |
#4
|
||||
|
||||
Unless the document has been saved at some earlier time, "ActiveDocument.Save" is inappropriate - you need to use "ActiveDocument.SaveAs" or "ActiveDocument.SaveAs2" before the IF test and give the document a valid path and name.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I will try that macropod! thanks a million
|
Tags |
runtime, templates |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Saving as ( PowerPoint Macro-Enabled Slide Show )?? | delete123 | PowerPoint | 2 | 04-10-2013 05:38 AM |
Macro Disappears from Template | Andrew H | Word | 1 | 11-26-2012 10:49 PM |
Word template containing macro + hotkeys | b0x4it | Word | 4 | 05-19-2011 06:37 PM |
Macro to open template not working | Brandi | Mail Merge | 2 | 06-24-2010 09:29 AM |
Macro to determine attached template | zippyaus | Word VBA | 0 | 03-02-2010 02:05 AM |