View Single Post
 
Old 12-08-2012, 09:21 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit 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

Whether there is any 'inappropriate' code really depends on whether the document contains the things referred to in, for example ".Fields(3).Result" and ".Variables.Item("Date1").Value". Combined, the code could become:
Code:
Sub AutoNew()
Dim InvoiceFile As String, InvNum As String, myDate As Date, StrPath As String
'Set the file save path.
StrPath = "G:\Sales Invoice\"
'Save ini file in the Word startup folder.
InvoiceFile = Options.DefaultFilePath(wdStartupPath) & "\Invoice.ini"
'or, by using the following line, the Workgroup folder
'InvoiceFile = Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\Invoice.ini"
InvNum = System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum")
'If there is no InvoiceNumber reference in the ini file
'Create one and set the number to 1, otherwise increment the number
If InvNum = "" Then
  InvNum = 1
Else
  InvNum = InvNum + 1
End If
System.PrivateProfileString(InvoiceFile, "InvoiceNumber", "InvNum") = InvNum
With ActiveDocument
  'Set the starting date with the value of a field
  myDate = .Fields(3).Result
  .Variables("Date1").Value = Format(myDate + 7, "dd MMMM yyyy")
  .CustomDocumentProperties("InvNum") = InvNum
  .Fields.Update
  .SaveAs2 FileName:=StrPath & "Invoice #" & InvNum, Fileformat:=wdFormatPDF
End With
End Sub
However, I doubt the validity of saving a document immediately it's created (and before you'd actually input any relevant invoice content) as a PDF.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote