C
chris_huh
I have made a template which just puts in a date range then autosaves
the file to a particular name when you close it. This create a new
document, but all the macro coding from the template file is copied
into the document. How can you set it so that the coding from the
template isn't copied into the document?
I would also prefer if the file isn't saved on close, but if the name
and location of the document is just set by the macro (so when you go
file>save it still lets you change the name and location if you want).
But i coulnd't get it to go to the right directory.
This is the code i have:
Private Function WeekStart() As Date
Dim wday As Byte
wday = Weekday(Date)
Select Case wday
Case 1
WeekStart = Date
Case 2
WeekStart = Date - 1
Case 3
WeekStart = Date - 2
Case 4
WeekStart = Date - 3
Case 5
WeekStart = Date - 4
Case 6
WeekStart = Date - 5
Case 7
WeekStart = Date - 6
End Select
End Function
Private Sub Document_Close()
Sunday = Format(WeekStart() + 7, "d")
Saturday = Format(WeekStart() + 13, "d MMM yy")
FileTitle = Sunday & " - " & Saturday & ".doc"
ActiveDocument.SaveAs "J:\Editorial\Magellan\Sickness Absence\Afghan\"
& FileTitle
End Sub
Private Sub Document_New()
Selection.GoTo What:=wdGoToBookmark, Name:="DateRange"
Selection.InsertBefore Format(WeekStart() + 7, "dddd, d MMMM")
Selection.InsertAfter " to "
Selection.InsertAfter Format(WeekStart() + 13, "dddd, d MMMM yyyy")
End Sub
Thats all in the ThisDocument module.
Thanks
the file to a particular name when you close it. This create a new
document, but all the macro coding from the template file is copied
into the document. How can you set it so that the coding from the
template isn't copied into the document?
I would also prefer if the file isn't saved on close, but if the name
and location of the document is just set by the macro (so when you go
file>save it still lets you change the name and location if you want).
But i coulnd't get it to go to the right directory.
This is the code i have:
Private Function WeekStart() As Date
Dim wday As Byte
wday = Weekday(Date)
Select Case wday
Case 1
WeekStart = Date
Case 2
WeekStart = Date - 1
Case 3
WeekStart = Date - 2
Case 4
WeekStart = Date - 3
Case 5
WeekStart = Date - 4
Case 6
WeekStart = Date - 5
Case 7
WeekStart = Date - 6
End Select
End Function
Private Sub Document_Close()
Sunday = Format(WeekStart() + 7, "d")
Saturday = Format(WeekStart() + 13, "d MMM yy")
FileTitle = Sunday & " - " & Saturday & ".doc"
ActiveDocument.SaveAs "J:\Editorial\Magellan\Sickness Absence\Afghan\"
& FileTitle
End Sub
Private Sub Document_New()
Selection.GoTo What:=wdGoToBookmark, Name:="DateRange"
Selection.InsertBefore Format(WeekStart() + 7, "dddd, d MMMM")
Selection.InsertAfter " to "
Selection.InsertAfter Format(WeekStart() + 13, "dddd, d MMMM yyyy")
End Sub
Thats all in the ThisDocument module.
Thanks