Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 12-08-2012, 09:21 PM
macropod's Avatar
macropod macropod is offline Please help me to combine these code together Windows 7 64bit Please help me to combine these code together Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
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
 



Similar Threads
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
Please help me to combine these code together Combine two forms into one lwisniewski Word VBA 3 12-24-2010 03:45 PM
Please help me to combine these code together Combine pst files? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:56 PM.


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