Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Run Macro On Exit Is Not Copied In Copied Document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George Lee - 20 Apr 2007 19:18 GMT
I am creating a copy of an existing document with the following code:

   Dim targetDocument As Document
   Set targetDocument = myDocument.Application.Documents.Add
("d:\samples\MyDocument.doc")

The file opens fine but on some form fields, the Run Macro On Exit becomes
blank, even through the macro being run is in that document. How do I prevent
the Run Macro from being stripped?
Jean-Guy Marcil - 20 Apr 2007 20:20 GMT
George Lee was telling us:
George Lee nous racontait que :

> I am creating a copy of an existing document with the following code:
>
[quoted text clipped - 5 lines]
> becomes blank, even through the macro being run is in that document.
> How do I prevent the Run Macro from being stripped?

I see two problems, one is probably an oversight on your part when you
posted:

1) Set targetDocument = myDocument.Application
   what is "myDocument" in that line?

2) Documents.Add expects a template as a parameter, not a document. You are
using a document, so I would not be surprised that things do not go as you
want... The link between the form fields and their macros are broken when
when Word is forced to create a document from a document as if it was trying
to create a new document from a template.

Why are you doing this? What is your overall goal?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

George Lee - 25 Apr 2007 16:32 GMT
The first code line example is an oversight. However, the second was
intended. Using a dot file keeps the macro links. Thanks. However, in
general, I use that line to create a copy of a document (as a .doc), rather
than opening the original document. Is that way not perferred?

> George Lee was telling us:
> George Lee nous racontait que :
[quoted text clipped - 22 lines]
>
> Why are you doing this? What is your overall goal?
Jean-Guy Marcil - 25 Apr 2007 20:16 GMT
George Lee was telling us:
George Lee nous racontait que :

> The first code line example is an oversight. However, the second was
> intended. Using a dot file keeps the macro links. Thanks. However, in
> general, I use that line to create a copy of a document (as a .doc),
> rather than opening the original document. Is that way not perferred?

Documents.Add is not intended to be used to make copy of existing documents,
but to create documents from templates,or create templates from templates.
So if you use it to some other end, you may get unexpected behaviour...

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.