I have a template that generates a standard letter for a user based on
inputs. The macros are used to generate the correct text given a users
input. The template works well. However, sometimes we will need to access
the document later on. I do not want the users to run the macros again. Is
there a way to strip the macros out of it and just save the file? My code
ends with:

If Response = vbYes Then
date2 = Format(Now, "MM-d-yyyy")
filetypename1 = strfilename & " " & date2
ChangeFileOpenDirectory "J:\PIH\ENGINEER\CFP\"
MsgBox filetypename1, vbOKOnly, "File name would be: "
ActiveDocument.SaveAs FileName:=filetypename1,
FileFormat:=wdFormatDocument, AddToRecentFiles:=True
End If

Any help would be appreciated!

Re: save file wihout macros by Jay

Jay
Fri Jun 27 11:29:46 PDT 2008

Mathew wrote:
> I have a template that generates a standard letter for a user based on
> inputs. The macros are used to generate the correct text given a
> users input. The template works well. However, sometimes we will
> need to access the document later on. I do not want the users to run
> the macros again. Is there a way to strip the macros out of it and
> just save the file? My code ends with:
>
> If Response = vbYes Then
> date2 = Format(Now, "MM-d-yyyy")
> filetypename1 = strfilename & " " & date2
> ChangeFileOpenDirectory "J:\PIH\ENGINEER\CFP\"
> MsgBox filetypename1, vbOKOnly, "File name would be: "
> ActiveDocument.SaveAs FileName:=filetypename1,
> FileFormat:=wdFormatDocument, AddToRecentFiles:=True
> End If
>
> Any help would be appreciated!

You are mistaken about the mechanism -- the macros are not saved in the
document, they remain in the template only. The macros are available when
the document is open because the document has a reference to the template.
(And that reference is valid only if the template is accessible to the
current user -- if you email the document to a computer that doesn't have
access to the template, the macros won't be available.)

You can remove the reference by attaching a different template, such as the
Normal.dot template, to the document before saving. Add this line to your
code, just before or just after the ChangeFileOpenDirectory statement:

ActiveDocument.AttachedTemplate = NormalTemplate

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.



Re: save file wihout macros by fumei

fumei
Fri Jun 27 11:31:37 PDT 2008

If the macros are in the template file, then if the template file is
accessible, the code is as well.

In other words, the code is not actually in the documents.

Unless what you mean by "template" is not, in fact, a real template.

Mathew wrote:
>I have a template that generates a standard letter for a user based on
>inputs. The macros are used to generate the correct text given a users
>input. The template works well. However, sometimes we will need to access
>the document later on. I do not want the users to run the macros again. Is
>there a way to strip the macros out of it and just save the file? My code
>ends with:
>
>If Response = vbYes Then
> date2 = Format(Now, "MM-d-yyyy")
> filetypename1 = strfilename & " " & date2
> ChangeFileOpenDirectory "J:\PIH\ENGINEER\CFP\"
> MsgBox filetypename1, vbOKOnly, "File name would be: "
> ActiveDocument.SaveAs FileName:=filetypename1,
>FileFormat:=wdFormatDocument, AddToRecentFiles:=True
> End If
>
>Any help would be appreciated!

--
Message posted via http://www.officekb.com


Re: save file wihout macros by Mathew

Mathew
Fri Jun 27 12:16:02 PDT 2008

Jay, Fumei via OfficeKB.com: Thanks for the information!

Jay: I used your approach and it worked very well, thanks again!

"Jay Freedman" wrote:

> Mathew wrote:
> > I have a template that generates a standard letter for a user based on
> > inputs. The macros are used to generate the correct text given a
> > users input. The template works well. However, sometimes we will
> > need to access the document later on. I do not want the users to run
> > the macros again. Is there a way to strip the macros out of it and
> > just save the file? My code ends with:
> >
> > If Response = vbYes Then
> > date2 = Format(Now, "MM-d-yyyy")
> > filetypename1 = strfilename & " " & date2
> > ChangeFileOpenDirectory "J:\PIH\ENGINEER\CFP\"
> > MsgBox filetypename1, vbOKOnly, "File name would be: "
> > ActiveDocument.SaveAs FileName:=filetypename1,
> > FileFormat:=wdFormatDocument, AddToRecentFiles:=True
> > End If
> >
> > Any help would be appreciated!
>
> You are mistaken about the mechanism -- the macros are not saved in the
> document, they remain in the template only. The macros are available when
> the document is open because the document has a reference to the template.
> (And that reference is valid only if the template is accessible to the
> current user -- if you email the document to a computer that doesn't have
> access to the template, the macros won't be available.)
>
> You can remove the reference by attaching a different template, such as the
> Normal.dot template, to the document before saving. Add this line to your
> code, just before or just after the ChangeFileOpenDirectory statement:
>
> ActiveDocument.AttachedTemplate = NormalTemplate
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
>
>
>