Why does macro work in VB but not in Word

D

Dave Neve

Hi

Still a total novice (and for a long time to be), I've finally got the bit
of code below to work (given recently in the group)

Sub AutoOpen()
If ActiveDocument.Name = "Mydoc.doc" Then
Myform.Show
End If
End Sub


but only when 'Mydoc.doc is opened and Visual Basics too.

From Visual Basics, when I execute the code, Myform appears but when I do it
from Mydoc.doc alone, nothing happens. (Tools, Macro and then I select the
macro and click it)

Why isn't the code activated the moment I open Mydoc.doc when I activate my
macro?

Thanks in advance
 
H

Helmut Weber

Hi Dave,
first, I don't know, what's wrong.
Second, are we talking about VB (Visual Basic)
or VBA (Visual Basic for Applications),
where VB is a programming language independant
from MS-Office and VBA is the language integrated
in office, though still in some respects different
in Word or Excel or Outlook and above all in Access.
And VBE is the Visual Basic for Applications Editor.
Where did you put the macro? Is it in Normal.dot?
What version of Word have you got?
MsgBox Application.Version
Is it a localized version? (german, french, spanish...)
Why isn't the code activated the moment I open
Mydoc.doc when I activate my macro?
Sorry again for saying so, but the above sentence makes
no sense to me: "...the moment I open Mydoc.doc when I
activate my macro" refers to a situation where you would
run the macro in the very same moment that it should be
activated by automation???
Have you got more than one macro named autoopen in
different modules? As far as I see, only the last one
is triggered, e.g. autoopen in Modul1 and autoopen in
Modul2: only autoopen in modul2 is activated.
Don't give up!
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 
D

Dave Neve

Hi

I should have said that I have VBA as it's opened through Word 2002 on XP

Thanks to your remarks concerning 'scope', Ithe first problem is solved.

As for 'autoamation', I want to say that even with the macro in Normal.dot,
there is still one thing I need to do which surprise me to get it to work

1 I still need to open Visual Basic Application and run the macro

Looking at the code, I kind of imagined that when I open Mydoc.doc and
activate my macros (cos of the security setting) , then they would run on
their own without any further intervention from me (at least this macro cos
the condition has been fulfilled in that "mydoc.doc" is open. (But it
doesn't)

In other words, why do I have to open VBA as well as Mydoc.doc and click on
'run'?


I appreciate the help as it's clear that I haven't really grasped VBA yet.

Thanks
 
H

Helmut Weber

Hi Dave,
as Jonathan supposed, make sure, that there is only
one "autoopen" in all (!) of your projects. I bet you
have experimented a lot and lost control over all
autoopen-macros you have created.
As a beginner, restrict yourself to 1 single project.
Preferably in normal.dot.
Don't dim Myform. In one example, you have created
a variable "Myform" of type variant that supersedes
the object "Myform" in the very scope of that sub.
So, "Myform" is a variable there, whereas "myform.show"
requires an object having a method "show".
A variable doesn't have a method.
Keep on trying!
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 

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