Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-08-2012, 08:54 PM
lbf200n lbf200n is offline Please help me to combine these code together Windows 7 64bit Please help me to combine these code together Office 2007
Novice
Please help me to combine these code together
 
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
 



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 10:18 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