disable macros for office 03

A

Associates

Hi,

I was wondering if i could get some help here. I'd like to be able to
disable all macros created/written in a document. What happens is that some
of our report documents have got some macros in it. We'd like to turn them
off so that our clients won't have to deal with macros when they receive our
reports. So my plan is to embed a code that would strip the macro off before
closing the document.

Here is the code i use
Private Sub oApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
Dim msg1, msg2 As String

msg1 = "Attempting to disable macros..." + vbNewLine

' turn off macro

msg2 = "You're about to close the document"

MsgBox msg1 & msg2
End Sub

I found the following code from the internet as follows
WordBasic.DisableAutoMacros 1

I think WordBasic is for office 95 or something. Then, i try the following
code but unable to find "disablemacro" method

Application.activedocument...

Your help would be greatly appreciated.

Thank you in advance
 
G

Gordon Bentley-Mix

The correct syntax is:

WordBasic.DisableAutoMacros 1

But I'm really not sure how much that's going to help you...
--
Cheers!
Gordon
~fighting with a tarbaby~

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
G

Gordon Bentley-Mix

This is not the right approach. You should put the macros into the template
that the report is based on. Documents based on the template won't have any
code in them, and unless your clients have access to the template, the
template code won't even enter into the picture.

In addition, the WordBasic command you've mentioned (which, BTW, still works
with later versions of Word) still isn't going to achieve your desired
result. Since it appears from your code sample that you plan on using this
command when you close the document, all that will happen is that the macros
won't run after the document is closed - and they wouldn't anyway.
WordBasic.DisableAutoMacros 1 doesn't set some sort of persistent flag in the
document to turn off the macros. Its intended use (from the VBA help topic on
Auto Macros) is:

In a macro that might trigger an auto macro, you can use
[WordBasic.DisableAutoMacro] to prevent auto macros from running.

If you're not going to use a template and insist on putting your code into
the document itself, then you'll need to do something else - possibly with a
document variable that gets evaluated in an AutoOpen macro and that the
report "author" can set (using a nice, user-friendly interface of your
design) before sending the report to the client. See my post in the thread
"How to make a word macro to execute only once?" for an idea of how this
could be achieved.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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