save file wihout macros

M

Mathew

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!
 
J

Jay Freedman

Mathew said:
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
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
F

fumei via OfficeKB.com

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

Mathew

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top