I
Ithaca
Hello, it's been a while since I've posted my problems here but I'm still
having the same ones... I've got a macro that will insert a form number in a
document (where ever the cusor is) and it works well. When I tried insert
the option to omit the last page from printing I ran into issues with
variables (as in I'm not sure how to use them correctly). The code uses
multiple message boxes to get all the info required and Jezebel suggested
using a userform. I've got that created but I'm not sure how to go about
setting it up for use with my macro (assigning buttons/fields). I'm
discovering that I may be in a little over my head with this stuff so your
help would be GREATLY appreciated
I'll post the code for the macro, the userform, and the "omit last page
print" code that Jezebel suggested. Can you help me combine these to
hopefully work using the userform. Thanks
Here's the code for the macro:
Dim NumCopies As String
Dim StartNum As String
Dim Counter As Long
Dim oRng As Range
If MsgBox("The copy number will appear at the insertion point." _
& " Is the cursor at the correct position?", _
vbYesNo, "Placement") = vbNo Then End
If ActiveDocument.Saved = False Then
If MsgBox("Do you want to save any changes before" & _
" printing?", vbYesNoCancel, "Save document?") _
= vbYes Then
ActiveDocument.Save
End If
End If
StartNum = Val(InputBox("Enter the starting number.", _
"Starting Number", 60099444))
NumCopies = Val(InputBox("Enter the number of copies that" & _
" you want to print", "Copies", 1))
ActiveDocument.Bookmarks.Add Name:="CopyNum", Range:=Selection.Range
Set oRng = ActiveDocument.Bookmarks("CopyNum").Range
Counter = 0
If MsgBox("Are you sure that you want to print " _
& NumCopies & " numbered " & " copies of this document", _
vbYesNoCancel, "On your mark, get set ...?") = vbYes Then
While Counter < NumCopies
oRng.Delete
oRng.Text = StartNum
Dim sCurrentPrinter As String
Dim sFormPrint As String
sCurrentPrinter = Application.ActivePrinter
Application.ActivePrinter = "\\AMPACPRINT\05025_82_9k on NE02:"
Application.PrintOut
Application.ActivePrinter = sCurrentPrinter
StartNum = StartNum + 1
Counter = Counter + 1
Wend
End If
End Sub
Here's the code for the "omit last page":
Select Case MsgBox("Do you want to print the last page?", vbYesNoCancel)
Case vbYes
ActiveDocument.PrintOut
Case vbNo
ActiveDocument.PrintOut From:=1,
To:=ActiveDocument.BuiltInDocumentProperties("Number of pages") - 1
Case Else
End Select
And finally the userform code...
Private Sub CancelMacro_Click()
End Sub
Private Sub FormNumber_Click()
End Sub
Private Sub PrintLastPage_Click()
End Sub
Private Sub RunMacro_Click()
End Sub
If you've made it this far I appreciate it and would be forever grateful!
Also, if you could point me to some tutorials regarding this stuff so that I
don't have to bother everyone as much in the future...
having the same ones... I've got a macro that will insert a form number in a
document (where ever the cusor is) and it works well. When I tried insert
the option to omit the last page from printing I ran into issues with
variables (as in I'm not sure how to use them correctly). The code uses
multiple message boxes to get all the info required and Jezebel suggested
using a userform. I've got that created but I'm not sure how to go about
setting it up for use with my macro (assigning buttons/fields). I'm
discovering that I may be in a little over my head with this stuff so your
help would be GREATLY appreciated
I'll post the code for the macro, the userform, and the "omit last page
print" code that Jezebel suggested. Can you help me combine these to
hopefully work using the userform. Thanks
Here's the code for the macro:
Dim NumCopies As String
Dim StartNum As String
Dim Counter As Long
Dim oRng As Range
If MsgBox("The copy number will appear at the insertion point." _
& " Is the cursor at the correct position?", _
vbYesNo, "Placement") = vbNo Then End
If ActiveDocument.Saved = False Then
If MsgBox("Do you want to save any changes before" & _
" printing?", vbYesNoCancel, "Save document?") _
= vbYes Then
ActiveDocument.Save
End If
End If
StartNum = Val(InputBox("Enter the starting number.", _
"Starting Number", 60099444))
NumCopies = Val(InputBox("Enter the number of copies that" & _
" you want to print", "Copies", 1))
ActiveDocument.Bookmarks.Add Name:="CopyNum", Range:=Selection.Range
Set oRng = ActiveDocument.Bookmarks("CopyNum").Range
Counter = 0
If MsgBox("Are you sure that you want to print " _
& NumCopies & " numbered " & " copies of this document", _
vbYesNoCancel, "On your mark, get set ...?") = vbYes Then
While Counter < NumCopies
oRng.Delete
oRng.Text = StartNum
Dim sCurrentPrinter As String
Dim sFormPrint As String
sCurrentPrinter = Application.ActivePrinter
Application.ActivePrinter = "\\AMPACPRINT\05025_82_9k on NE02:"
Application.PrintOut
Application.ActivePrinter = sCurrentPrinter
StartNum = StartNum + 1
Counter = Counter + 1
Wend
End If
End Sub
Here's the code for the "omit last page":
Select Case MsgBox("Do you want to print the last page?", vbYesNoCancel)
Case vbYes
ActiveDocument.PrintOut
Case vbNo
ActiveDocument.PrintOut From:=1,
To:=ActiveDocument.BuiltInDocumentProperties("Number of pages") - 1
Case Else
End Select
And finally the userform code...
Private Sub CancelMacro_Click()
End Sub
Private Sub FormNumber_Click()
End Sub
Private Sub PrintLastPage_Click()
End Sub
Private Sub RunMacro_Click()
End Sub
If you've made it this far I appreciate it and would be forever grateful!
Also, if you could point me to some tutorials regarding this stuff so that I
don't have to bother everyone as much in the future...