View Single Post
 
Old 12-08-2012, 08:54 PM
lbf200n lbf200n is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Dec 2012
Posts: 3
lbf200n is on a distinguished road
Default Please help me to combine these code together

I am new to this form, and i have read a large amount of the posts when i was needing help to create a word document with macro functions.

I have got these three macros that can do there things for me: auto calculate date, auto generate number and auto save with the name formate that i like, all these are copied or copy and changed a little with my poor coding knowledge.

Could you please firstly check if there is any inappropriate in the code.

and what i really need is to combine all these three macros into one, so every time i dont have to run all of these three individually, one click will do all the work for me

Codes here:
Code:
Option Explicit
 
Sub AutoNew()
Dim InvoiceFile As String, InvNum As String
'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
  .CustomDocumentProperties("InvNum") = InvNum
  .Fields.Update
End With
End Sub
Code:
Option Explicit
 
Sub DateAdd()
Dim myDate As Date
Dim myRng As Range
  'Set the starting date with the value of a field
  Set myRng = ActiveDocument.Fields(3).Result
  myDate = myRng
  'Tip - Here the field index is one because it is the first field in the document.
  'If you don't know the field index number? Just select the field and run the following line of code:
  'MsgBox Selection.Fields(1).Index
  With ActiveDocument.Variables
    .Item("Date1").Value = Format(myDate + 7, "dd MMMM yyyy")
  End With
  ActiveDocument.Fields.Update
lbl_Exit:
Exit Sub
End Sub
Code:
Sub SaveMe()
Dim StrPath As String, InvNum2 As String
 
With ActiveDocument
InvNum2 = .CustomDocumentProperties("InvNum")
End With
 
 
StrPath = "G:\Sales Invoice\"
ActiveDocument.Saveas FileName:=StrPath & "Invoice #" & InvNum2, Fileformat:=wdFormatPDF
End Sub

Last edited by macropod; 12-08-2012 at 09:16 PM. Reason: Removed personalisation
Reply With Quote