![]() |
#2
|
||||
|
||||
![]()
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to combine many paragraphs in one paragraph? | Jamal NUMAN | Word | 25 | 03-08-2013 04:31 AM |
How to combine individual tab into one master tab | angie.chang | Excel | 1 | 07-27-2012 10:06 PM |
![]() |
lwisniewski | Word VBA | 3 | 12-24-2010 03:45 PM |
![]() |
markg2 | Outlook | 2 | 04-26-2010 03:09 PM |
How do you combine two contact folders? | waikoloavrm | Outlook | 0 | 04-12-2010 02:31 PM |