Object required

D

Dave Neve

Hi

I'm embarrased to ask so many questions on one stupid macro but.....

The following code doesn't work when inserterd into 'this document' of a
project where the userform also exists.

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


The error is 'object required' which I find strange as the Userform is in
the same Project

However, when inserted into the code of the object itself (the userform), it
works.

The title of my window is Microsoft Visual Basic-Mydoc[ThisDocument (Code)]
so I think it's natural to assume that 'Mydoc' ='This document' and that
therefore the code should work when inserted into ThisDocument.

So the question is 'What is the relationship between 'XXX.doc' (the open
..doc) and 'This
document' in VBA

Thanks in advance again.
 
J

Jezebel

You haven't told the system what 'MyForm' refers to. When the code reaches
the MyForm.Show statement it's expecting an object with a Show method: but
all you've got at that point is an empty variant.

Dim MyForm as frmMyForm (whatever you've set as the Name of your
UserForm)
Set MyForm = New frmMyForm
MyForm.Show
 

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