Reputation: 82
Okay,
so for my apprenticeship I need to keep record of what I do everyday. Since this is going to be a long doc, I wrote a VBA script which already writes stuff that stays the same, like the date, in there.
Problem is, the format is supposed to be one week per page. Means, when I arrive at saturday, the script would have to jump to the beginning of the next page(and probably fill the resulting space with paragraphs). And I have absolutely no clue if there is any function that could help me with that. I think there should be one tho, this doesn't Sound like a too exotic Problem.
Now this is no crucial problem, but it's annoying nonetheless and I'd like to know if there is any solution for this. Research so far didn't do the trick either.
Have some code if that helps understanding. Ist basically about the commented part:
For i = InitDate To endDate
jump:
If CurrentDate = endDate Then GoTo EndSub
x = x + 1
strWeekday = weekday(CurrentDate, vbUseSystemDayOfWeek)
txtStr = Format(CurrentDate, "dddddd")
With Selection
.Font.Bold = True
.Font.Underline = True
.TypeText Text:=txtStr
.TypeParagraph
If x = 4 Then GoTo Thursday
If x = 5 Then GoTo Friday
'If x = 6 Then GoTo NewSheet
If x = 6 Then x = 0
.TypeParagraph
End With
CurrentDate = CurrentDate + 1
Next i
Upvotes: 2
Views: 1924
Reputation: 17041
ActiveDocument.StoryRanges(wdMainTextStory).InsertAfter ChrW(12)
will insert a hard page break at the end of your text. (Or, in general, r.InsertAfter ChrW(12)
for a Range
variable r
. Then you can carry on from there!
Now that you've added code, I can show you more. However, since you didn't include all the code, I can't provide something that will run as is. Also, I think you can replace CurrentDate
with i
(or vice versa).
For i = InitDate To endDate
jump:
If CurrentDate = endDate Then GoTo EndSub
x = x + 1
strWeekday = weekday(CurrentDate, vbUseSystemDayOfWeek)
txtStr = Format(CurrentDate, "dddddd")
With Selection
.Font.Bold = True
.Font.Underline = True
.TypeText Text:=txtStr
.TypeParagraph
End With
' ** By the way, I would suggest you not GoTo out of a With block - that strikes me as likely to cause confusion later on.
If x = 4 Then GoTo Donnerstag
If x = 5 Then GoTo Freitag
'If x = 6 Then GoTo NewSheet
If x = 6 Then ' ** Try this
Selection.InsertAfter ChrW(12)
Selection.Collapse wdCollapseEnd
End If
If x = 6 Then x = 0
Selection.TypeParagraph
CurrentDate = CurrentDate + 1
Next i
Upvotes: 1