Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-22-2013, 12:37 PM
ReviTULize ReviTULize is offline Macro-enabled Template Windows 7 64bit Macro-enabled Template Office 2007
Novice
Macro-enabled Template
 
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
  #2  
Old 01-29-2013, 10:01 PM
macropod's Avatar
macropod macropod is offline Macro-enabled Template Windows 7 64bit Macro-enabled Template Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 01-30-2013, 07:19 AM
ReviTULize ReviTULize is offline Macro-enabled Template Windows 7 64bit Macro-enabled Template Office 2007
Novice
Macro-enabled Template
 
Join Date: Dec 2011
Posts: 20
ReviTULize is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 01-30-2013, 04:07 PM
macropod's Avatar
macropod macropod is offline Macro-enabled Template Windows 7 64bit Macro-enabled Template Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 02-01-2013, 01:46 PM
ReviTULize ReviTULize is offline Macro-enabled Template Windows 7 64bit Macro-enabled Template Office 2007
Novice
Macro-enabled Template
 
Join Date: Dec 2011
Posts: 20
ReviTULize is on a distinguished road
Default

I will try that macropod! thanks a million
Reply With Quote
Reply

Tags
runtime, templates



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro-enabled Template 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
Macro-enabled Template 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft