From: chris_huh on
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
From: Jonathan West on

"chris_huh" <chris.huh(a)gmail.com> wrote in message
news:747b26aa-6ca5-4d56-b369-0dbee977fd0b(a)m45g2000hsb.googlegroups.com...
>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?

You are mistaken. Unless you are doing something quite different from what
you describe, the document does not contain the code. It contains a
reference to the template, and therefore the code in the template is
available when you open the document. If you move the document to a PC which
does not have the template, the macro will no longer run.


>
> 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.

Change this line of code


> ActiveDocument.SaveAs "J:\Editorial\Magellan\Sickness Absence\Afghan\"
> & FileTitle


To this

With Dialogs(wdDialogFileSaveAs)
.Name = "J:\Editorial\Magellan\Sickness Absence\Afghan\" & FileTitle
.Show
End With

Then you can cancel the save or change the folder and filename if you want
to.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


From: chris_huh on
On 26 Jun, 12:35, "Jonathan West" <jw...(a)mvps.org> wrote:
> "chris_huh" <chris....(a)gmail.com> wrote in message
>
> news:747b26aa-6ca5-4d56-b369-0dbee977fd0b(a)m45g2000hsb.googlegroups.com...
>
> >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?
>
> You are mistaken. Unless you are doing something quite different from what
> you describe, the document does not contain the code. It contains a
> reference to the template, and therefore the code in the template is
> available when you open the document. If you move the document to a PC which
> does not have the template, the macro will no longer run.
>
>
>
> > 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.
>
> Change this line of code
>
> > ActiveDocument.SaveAs "J:\Editorial\Magellan\Sickness Absence\Afghan\"
> > & FileTitle
>
> To this
>
> With Dialogs(wdDialogFileSaveAs)
>     .Name = "J:\Editorial\Magellan\Sickness Absence\Afghan\" & FileTitle
>     .Show
> End With
>
> Then you can cancel the save or change the folder and filename if you want
> to.
>
> --
> Regards
> Jonathan West - Word MVPwww.intelligentdocuments.co.uk
> Please reply to the newsgroup

Ah yes i see. In the projects box (top left) it lists the template and
the document. The ThisDocument thing under the document is blank. I
think you can see what i'm going to ask next. Is there a way to remove
this template reference so when you open that document there is no
Enable Macros request?

I also changed that code for the saving. That now allows you to change
the location and name (great, thanks) but is there a way for that to
happen when you click Save, rather than close. I guess you woudl take
that bit out of the Document_Close sub, but what would i put it in?

Thanks so much
From: Jonathan West on


<<Ah yes i see. In the projects box (top left) it lists the template and
the document. The ThisDocument thing under the document is blank. I
think you can see what i'm going to ask next. Is there a way to remove
this template reference so when you open that document there is no
Enable Macros request?>>

Yes. Add the following line to your macro at some suitable point.

ActiveDocument.AttachedTemplate = NormalTemplate

Then the document will be attached to Normal.dot, not to the template.

Alternatively, digitally sign your template so that it is regarded as being
trusted, and the warning will no longer appear. If it is just for local use,
you can create your own certificate. On the Windows Start menu, go to
Microsoft Office, then Microsoft Office Tools. In that submenu you should
see "Digital Certificate for VBA Projects". Click that and follow the
instructions.


<<I also changed that code for the saving. That now allows you to change
the location and name (great, thanks) but is there a way for that to
happen when you click Save, rather than close. I guess you woudl take
that bit out of the Document_Close sub, but what would i put it in?>>

Create a new module, and create a routine in it called FileSave Put the code
I provided into that routine.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


From: chris_huh on
On 26 Jun, 14:00, "Jonathan West" <jw...(a)mvps.org> wrote:
> <<Ah yes i see. In the projects box (top left) it lists the template and
> the document. The ThisDocument thing under the document is blank. I
> think you can see what i'm going to ask next. Is there a way to remove
> this template reference so when you open that document there is no
> Enable Macros request?>>
>
> Yes. Add the following line to your macro at some suitable point.
>
> ActiveDocument.AttachedTemplate = NormalTemplate
>
> Then the document will be attached to Normal.dot, not to the template.
>
> Alternatively, digitally sign your template so that it is regarded as being
> trusted, and the warning will no longer appear. If it is just for local use,
> you can create your own certificate. On the Windows Start menu, go to
> Microsoft Office, then Microsoft Office Tools. In that submenu you should
> see "Digital Certificate for VBA Projects". Click that and follow the
> instructions.
>
> <<I also changed that code for the saving. That now allows you to change
> the location and name (great, thanks) but is there a way for that to
> happen when you click Save, rather than close. I guess you woudl take
> that bit out of the Document_Close sub, but what would i put it in?>>
>
> Create a new module, and create a routine in it called FileSave Put the code
> I provided into that routine.
>
> --
> Regards
> Jonathan West - Word MVPwww.intelligentdocuments.co.uk
> Please reply to the newsgroup

Thats got rid of the Enable Macros dialog, thanks.

I am not too proficient with macros and vba. Is a routine different to
a sub, etc. How would i do that. I made a new module (Module1 under
the Modules heading) and then put in:

Sub FileSave()

Sunday = Format(WeekStart() + 7, "d")
Saturday = Format(WeekStart() + 13, "d MMM yy")

FileTitle = Sunday & " - " & Saturday & ".doc"

With Dialogs(wdDialogFileSaveAs)
.Name = "J:\Editorial\Magellan\Sickness Absence\Afghan\" &
FileTitle
.Show
End With

End Sub

That didn't do anything.