Remove macro

A

Aad Langelaan

When I have programmed a .dot file and it is used so to create a .doc file, I
want to have the macro(VBA-code) part removed out of the document so it is a
document only without any vba code in it.
My reason is that you use the programming part to create a document, but
when the document is made, no programming is needed anymore to edit or update
the document. You will not have to answer the macro question also.
 
G

Graham Mayor

Documents created from templates with macros do not contain the macros. The
macros always remain within the template. You may be able to program the
macro to not run a second time e.g. by setting a document variable and only
run the macro according to the state of the variable.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Aad Langelaan

Thanks for the solution, but can you tell me how to set that variable.
I have been trying something like "looking" if it is a document what is
opened or a template, but did not succeed in that
 
G

Graham Mayor

Something like

Dim aVar As Variable
Dim oVars As Variables
Dim iNum As Integer
Set oVars = ActiveDocument.Variables
For Each aVar In oVars
If aVar.name = "varRunMacro" Then iNum = aVar.Index
Next aVar
If iNum = 0 Then
'If variable does not exist - create it and set its value to 1
oVars.Add name:="varRunMacro", Value:=1
End If
'If variable value is 1 then it's a new document, the macro may be run
If oVars("varRunMacro").Value = 1 Then
'do what you want with the document eg
MsgBox "Macro is running"
'set the value of the variable to 0
oVars("varRunMacro").Value = 0
Else 'the macro has been run so the macro may not be run again.
MsgBox "Macro not available"
End If

It may suffice simply to check whether the document has been saved eg

IF Len(ActiveDocument.Path) <> 0
'do your thing
End If


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Aad Langelaan

This works, but not the way I ment to.
the macro security is set to: Medium.
So every time the created doc is started, there is still the question to
enable or disable macro's.
That's what I want to get out of sight.
 
G

Graham Mayor

Then you need to set Word's macro security to trust installed templates and
addins (or in the case of Word 2007 put the template in a trusted folder
location). There will be no macro prompt then in either case.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Aad Langelaan

Settings are already so in Word 2003,
but we are not only using templates located at the computer itself, but we
use also
a lot of templates located on network drives.
And the major part of the created documents are also saved on network drives.
So the message still appears.
 
A

Aad Langelaan

I do not think, this is a solution.
The organisation I am is to big to get this kind of things accomplished.
Perhaps it is better to leave it be.

thanks anyway.
 

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