Hi Guys, I have a sign in sheet template that I use and have the following
code in it. It is supposed to print my template consecutive dates at the top
of each sheet as per my instructions in the vb code. Im sure this was working
correctly but now when I run it, it brings up random dates. If I enter 10
days from 01/01/08 I get dates in February and so on. Is there something I
may have done to the coding? Can someone have a look at ot and see what they
get? Any help on this would be appreciated.
Thanks
Scott
(PS I currently have the printing disabled in the code)
Sub PrintNumberedCopies()
Dim i As Long
Dim d As Date
Dim pStr As String
Dim oRng As Range
Dim NumCopies As Long
If MsgBox("The date 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
d = CDate(InputBox("Enter the starting date.", _
"Date", "1 / 1 / 2008"))
NumCopies = Val(InputBox("Enter the number of copies that" & _
" you want to print", "Copies", 1))
ActiveDocument.Bookmarks.Add Name:="Date", Range:=Selection.Range
Set oRng = ActiveDocument.Bookmarks("Date").Range
i = 0
If MsgBox("Are you sure that you want to print " _
& NumCopies & " dated " & " copies of this document", _
vbYesNoCancel, "On your mark, get set ...?") = vbYes Then
While i < NumCopies
oRng.Delete
d = DateAdd("d", i, d)
pStr = Format(d, "dddd dd MMMM, yyyy")
oRng.Text = pStr
oRng.Font.Size = "24"
' ActiveDocument.PrintOut
i = i + 1
Wend
End If
End Sub
David Sisson - 06 Feb 2008 14:44 GMT
In this line
> d = DateAdd("d", i, d)
You're adding the loop counter to the starting date then replacing the
starting date with the future date, so it increments exponentially
instead of incrementally.
Add one more variable
Dim dTmp as Variant
and replace these lines
> d = DateAdd("d", i, d)
> pStr = Format(d, "dddd dd MMMM, yyyy")
with this
dTmp = DateAdd("d", i, d)
pStr = Format(dTmp, "dddd dd MMMM, yyyy")
Scott R - 06 Feb 2008 20:56 GMT
Anyone told you your a legend lately!!
Thankyou!
> In this line
> > d = DateAdd("d", i, d)
[quoted text clipped - 14 lines]
> dTmp = DateAdd("d", i, d)
> pStr = Format(dTmp, "dddd dd MMMM, yyyy")
David Sisson - 06 Feb 2008 21:08 GMT