Thread: [Solved] Macro-enabled Template
View Single Post
 
Old 01-22-2013, 12:37 PM
ReviTULize ReviTULize is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Dec 2011
Posts: 20
ReviTULize is on a distinguished road
Default 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
Reply With Quote