Templates and default file names.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I have a purchase order form template and the order number is entered
manually into a field. Once the form is filled in i wish the user to print
to PDF. Is it possible to change the default file name of "document 1" to
"Purchase Order_(number in form field)" using macros.

Thanks and regards

Steve
 
Add the following macro to a toolbar button on your form. The macro assumes
that you have Acrobat as your PDF creation software and that the number you
want to use in the filename is in the form field Text1.

Sub SaveAndPrint()
Dim sCurrentPrinter As String
Dim bProtected As Boolean
Dim fName As String

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If

'Get content of form field
fName = ActiveDocument.FormFields("Text1").Result
ActiveDocument.SaveAs "Purchase Order _" & fName

'Print the document
sCurrentPrinter = ActivePrinter
ActivePrinter = "Adobe PDF"
Application.PrintOut FileName:=""
ActivePrinter = sCurrentPrinter

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Thanks for that Graham, works a treat.

Is it nesessary for the word document to be saved too as this is not
required. If so can i save to a location of my choice. Current directory
being D:my documents.

Thanks again in advanced.

Steve
 
A document doesn't have a name until it is saved!
To save it in your preferred location add the path to the filename. eg
ActiveDocument.SaveAs "D:\My Documents\Purchase Order _" & fName

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Hi Graham,

I have another issue which has come to light this morning which i'm hoping
you can shed some light on.

I've just upgraded from word 2003 to 2007, i have several forms some running
macro some not. Since installing 2007 the forms running macro which were
saved protected can be unprotect but cannot be re-protected. All the
protection settings are greyed out. The forms without macro running on them
are okand can be unprotected/re-protected. I still have 2003 installed and my
forms running macros cannot be protected either.

Regards

Steve
 
I have resisted the urge to install 2007 so cannot help.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top