Link to home
Start Free TrialLog in
Avatar of Genius123
Genius123Flag for United States of America

asked on

Outlook form vb script

Hello,

I have a script that generates a PDF.  Everything works, except I don't want the PDF to open.  There's a constant called openAfterExport but I keep getting errors when using it.  Here's my code.  Thanks.


Sub CommandButtonIntro_Click()

    'On Error Resume Next

JobYear = cstr(Year(Item.UserProperties("JobInitiatedDate")))

    Set objDoc = GetWordDocAll("\\TGPS13VM1\drawing$\Jobs\Task_Templates\Letter-Project Introduction - 2"+CDNTemplate+".dot")
    Call FillFieldsIntro(objDoc)
    objDoc.Application.ActiveDocument.AttachedTemplate = "Normal"'objDoc.Application.Options.PrintBackground = True
objDoc.application.Windows(1).WindowState = wdWindowStateMaximize

If MsgBox("Make your changes to the Word doc first, then click Yes to save.", _
   vbQuestion + vbYesNo) = vbYes Then
      objDoc.Application.ActiveDocument.SaveAs "\\TGPS13VM1\drawing$\Jobs-"+JobYear+"\"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")+"\"+Item.UserProperties("JobNumber")+" Intro"
End If

objDoc.ExportAsFixedFormat "\\TGPS13VM1\drawing$\Jobs-"+JobYear+"\"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")+"\"+Item.UserProperties("JobNumber")+" Intro.pdf",wdExportFormatPDF,true,wdExportOptimizeForPrint,wdExportAllDocument,OpenAfterExport

    'Call RestoreWordIntro
objDoc.Close wdDoNotSaveChanges
'objWord.Quit
          Set objDoc = Nothing
      Set objWord = Nothing

Call CommandButtonIntroCover


End Sub
Avatar of Neil Fleming
Neil Fleming
Flag of United Kingdom of Great Britain and Northern Ireland image

It's not just as simple as changing "OpenAfterExport" to "False" by any chance, is it? ie:

objDoc.ExportAsFixedFormat "\\TGPS13VM1\drawing$\Jobs-"+JobYear+"\"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")+"\"+Item.UserProperties("JobNumber")+" Intro.pdf",wdExportFormatPDF,true,wdExportOptimizeForPrint,wdExportAllDocument,False

Open in new window

Avatar of Genius123

ASKER

No it's not.  I will get an error saying undefined variable.  I have other constants defined, but I don't know how to define that one.  The other constants look like this:

Const wdExportAllDocument = 0
Const wdExportOptimizeForPrint = 0
Const wdExportDocumentContent = 0
Const wdExportFormatPDF = 17
Const wdExportCreateHeadingBookmarks = 1

I've tried this but it doesn't work:

const openAfterExport = false
ASKER CERTIFIED SOLUTION
Avatar of Neil Fleming
Neil Fleming
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah ha!  It worked!  I understand how it works now too.  It was a little bit of mystery before this.  Thanks for your help. :-)
glad to be of help