Re: How to make a word macro to execute only once? by Jonathan
Jonathan
Wed Jun 18 08:55:21 PDT 2008
<Luca.albanesi@gmail.com> wrote in message
news:fb7507c8-462d-4400-926a-cd4d5f130bd2@34g2000hsf.googlegroups.com...
> On 18 Giu, 13:06, "Jonathan West" <jw...@mvps.org> wrote:
>> <Luca.alban...@gmail.com> wrote in message
>>
>> news:6ce86c93-0571-43f3-bab9-7ad6abbf364b@m44g2000hsc.googlegroups.com...
>>
>>
>>
>>
>>
>> > Hi,
>>
>> > I've got this unusual problem to solve.
>>
>> > I have a Word Document Template (.dot) that is used by my co-workers
>> > to prepare offers for customers. This adds on top and bottom of the
>> > document our company logo and a few contact infos.
>>
>> > My co-workers asked me if I can show an alert when they close the
>> > document, asking "Do you want to save this document in the 'offers'
>> > directory? (Y/N)" and I made this through a macro, using the "close"
>> > event of the document. There are a few problems, though:
>>
>> > - This prompt happens everytime the user closes the file
>> > - This must not be displayed if the customer opens and closes it
>>
>> > My idea was to make it execute only once, so that the second time it
>> > won't be displayed... but how do I do it? How can I set a flag or
>> > something so that a macro is executed only once, or how can I delete a
>> > macro from scripts in VBA?
>>
>> > Thanks in advance!
>>
>> In Word, whan you have VBA stored in the template and you create a
>> document
>> based on the template, the VBA is not copied into the document. The VBA
>> remains available to you because the document includes a reference to the
>> template, so Word knows what template to look in for the VBA code.
>>
>> When you email the document to a customer who does not have the template,
>> none of the VBA code is present, and therefore will not execute.
>>
>> In short, you don't need to do anything.
>>
>> --
>> Regards
>> Jonathan West - Word MVPwww.intelligentdocuments.co.uk
>> Please reply to the newsgroup
>
> Hi Johnatan,
>
> thanks for your quick reply.
>
> This would solve the customer side of the problem, but the Lan part
> would still present itself.
>
> The template is available to all my co-workers, so when they open and
> close the document, the message would still present itself and they
> want to avoid it (unless that's the first time they save the
> document).
>
> I was thinking a solution that includes a connection to an access or
> MySQL database that stores the filename of the files so that the macro
> can put the filename when they're stored on the disk: if a name
> exists, then don't present the message. This is, if there's a smarter
> and easier method on Word.
>
There is an easier way. If you only want to display the dialog when the
document is first saved, then you can check the ActiveDocument.Path
property. If it is an empty string, then the document is newly-created and
has never been saved. If it isn't, then the document has been previously
saved. Your code can branch accordingly.
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup