Announcement

Collapse
No announcement yet.

Need Macro Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need Macro Help

    I had a similar question a few years ago, but I'm switching from excel to word to print my invoices. The macro I was using in excel doesn't work in word (obviously).

    What the macro does: when you run the macro it asks how many invoices you want to print.. you type in whatever (ie 100) and click ok. The program does the rest. It prints the invoice (2 copies bc we have 2 part carbonless paper) and increases it by 1 every time it prints the new invoice.

    You can tell it is opening a 100 invoices and clicking print on each. It is nice to use instead of having to do this manually, but now that my new invoice is in word, I'm back to having to type in each number and hit print.

    Any help would be greatly appreciated!

    Excel code for those that are curious:
    Sub PrintCopies_ActiveSheet()

    Dim CopiesCount As Long
    Dim copynumber As Long

    CopiesCount = Application.InputBox("How many copies do you want?", Type:=1)
    'Now the program wants you to input how many pages you like to print.
    'You can input 100 here.

    For copynumber = 1 To CopiesCount
    With ActiveSheet
    Range("G3").Value = Range("G3").Value + 1
    ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
    End With
    Next copynumber
    End Sub
    Owner of Titan Towing
    817.478.7201

    We have your towing needs covered!
    http://www.titantowing.net
    -------------------------------

    Interested in being a VIP member and donating to the site? Click here to become a paid member!

  • #2
    Figured it out!

    Sub PrintCopies_ActiveDocument()
    '
    ' PrintCopies_ActiveDocument Macro
    '
    '
    Dim Message As String, Title As String, Default As String, NumCopies As Long
    Dim Rng1 As Range

    ' Set prompt.
    Message = "Enter the number of copies that you want to print"
    ' Set title.
    Title = "Print"
    ' Set default.
    Default = "1"

    ' Display message, title, and default value.
    NumCopies = Val(InputBox(Message, Title, Default))
    SerialNumber = System.PrivateProfileString("C:\Users\Home\Desktop \Settings.Txt", _
    "MacroSettings", "SerialNumber")

    If SerialNumber = "" Then
    SerialNumber = 1
    End If

    Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
    Counter = 1

    While Counter < NumCopies + 1
    Rng1.Delete
    Rng1.Text = SerialNumber
    ActiveDocument.PrintOut Copies:=2, Collate:=True
    SerialNumber = SerialNumber + 1
    Counter = Counter + 1
    Wend

    'Save the next number back to the Settings.txt file ready for the next use.
    System.PrivateProfileString("C:\Users\Home\Desktop \Settings.txt", "MacroSettings", _
    "SerialNumber") = SerialNumber

    'Recreate the bookmark ready for the next use.
    With ActiveDocument.Bookmarks
    .Add Name:="SerialNumber", Range:=Rng1
    End With

    ActiveDocument.Save
    End Sub
    Owner of Titan Towing
    817.478.7201

    We have your towing needs covered!
    http://www.titantowing.net
    -------------------------------

    Interested in being a VIP member and donating to the site? Click here to become a paid member!

    Comment

    Working...
    X