Word Document

A

Alex

I'm trying to use the word document as a help file.
Before to open it, I'm checking whether it's already
opened. The checking is going fine. But, after that I get
an error message: "Object variable or With block variable
not set."

Dim MyWord As Object

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document

Dim strFileName As String, logFileIsOpened As Boolean

strFileName = "FileName"

logFileIsOpened = FileLocked(strFileName)

If logFileIsOpened = True Then

Set wrdDoc = wrdApp.Documents.Open(strFileName) ' Here
is the error !!!!!!!!!!!!!!!!!!!!!!!!!!!!
wrdDoc.Activate

Else

Set MyWord = GetObject(strFileName)
MyWord.Application.Visible = True
End If

Could anybody clarify it?

Thanks
 
J

John Nurick

Hi Alex,

The reason for the error is that you're referring to
wrdApp.Documents
before you've instantiated wrdApp.

However, if the document is already open in a running instance of Word,
Set wrdDoc = GetObject(strFileName)
should get hold of it. If it's not open, it should open it. So try
something like:

Dim strFileName as String
Dim wrdDoc As Word.Document
Dim wrdApp As Word.Application

On Error Resume Next
Set wrdDoc = GetObject(strFileName)
If wrdDoc Is Nothing then
MsgBox "COuldn't open " & strFilename
Exit Sub
End If
On Error Goto 0
Set wrdApp = wrdDoc.Application
....
 
A

Alex

Thanks a lot, John.
But, how could I open this file?
I'm trying to continue your code
(On Error Goto 0
Set wrdApp = wrdDoc.Application
.....).
Instead I'm using:
On Error GoTo 0
Set wrdApp = wrdDoc.Application.Documents.Open(strFileName)

The file is being opened perfectly but I'm getting the
error message "Run-time error '13': Type mismatch".

Regards,

Alex
-----Original Message-----
Hi Alex,

The reason for the error is that you're referring to
wrdApp.Documents
before you've instantiated wrdApp.

However, if the document is already open in a running instance of Word,
Set wrdDoc = GetObject(strFileName)
should get hold of it. If it's not open, it should open it. So try
something like:

Dim strFileName as String
Dim wrdDoc As Word.Document
Dim wrdApp As Word.Application

On Error Resume Next
Set wrdDoc = GetObject(strFileName)
If wrdDoc Is Nothing then
MsgBox "COuldn't open " & strFilename
Exit Sub
End If
On Error Goto 0
Set wrdApp = wrdDoc.Application
....





I'm trying to use the word document as a help file.
Before to open it, I'm checking whether it's already
opened. The checking is going fine. But, after that I get
an error message: "Object variable or With block variable
not set."

Dim MyWord As Object

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document

Dim strFileName As String, logFileIsOpened As Boolean

strFileName = "FileName"

logFileIsOpened = FileLocked(strFileName)

If logFileIsOpened = True Then

Set wrdDoc = wrdApp.Documents.Open(strFileName) ' Here
is the error !!!!!!!!!!!!!!!!!!!!!!!!!!!!
wrdDoc.Activate

Else

Set MyWord = GetObject(strFileName)
MyWord.Application.Visible = True
End If

Could anybody clarify it?

Thanks

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.
 
J

John Nurick

Comments inline.

Thanks a lot, John.
But, how could I open this file?
I'm trying to continue your code
(On Error Goto 0
Set wrdApp = wrdDoc.Application
....).
Instead I'm using:
On Error GoTo 0
Set wrdApp = wrdDoc.Application.Documents.Open(strFileName)
The file is being opened perfectly but I'm getting the
error message "Run-time error '13': Type mismatch".

Of course it gives you a type mismatch error. You've declared wrdApp as
a Word Application object, but that line returns a Word Document object.

In any case, since the document has already been opened by
Set wrdDoc = GetObject(strFileName)
why are you trying to open it a second time?

Regards,

Alex
-----Original Message-----
Hi Alex,

The reason for the error is that you're referring to
wrdApp.Documents
before you've instantiated wrdApp.

However, if the document is already open in a running instance of Word,
Set wrdDoc = GetObject(strFileName)
should get hold of it. If it's not open, it should open it. So try
something like:

Dim strFileName as String
Dim wrdDoc As Word.Document
Dim wrdApp As Word.Application

On Error Resume Next
Set wrdDoc = GetObject(strFileName)
If wrdDoc Is Nothing then
MsgBox "COuldn't open " & strFilename
Exit Sub
End If
On Error Goto 0
Set wrdApp = wrdDoc.Application
....





I'm trying to use the word document as a help file.
Before to open it, I'm checking whether it's already
opened. The checking is going fine. But, after that I get
an error message: "Object variable or With block variable
not set."

Dim MyWord As Object

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document

Dim strFileName As String, logFileIsOpened As Boolean

strFileName = "FileName"

logFileIsOpened = FileLocked(strFileName)

If logFileIsOpened = True Then

Set wrdDoc = wrdApp.Documents.Open(strFileName) ' Here
is the error !!!!!!!!!!!!!!!!!!!!!!!!!!!!
wrdDoc.Activate

Else

Set MyWord = GetObject(strFileName)
MyWord.Application.Visible = True
End If

Could anybody clarify it?

Thanks

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.
 
A

Alex

Thanks a lot again, John.
It's working now.
I've just added to your code after <Set wrdApp =
wrdDoc.Application> the following:

wrdApp.Activate
wrdApp.Visible = True

Regards,

Alex
-----Original Message-----
Comments inline.

Thanks a lot, John.
But, how could I open this file?
I'm trying to continue your code
(On Error Goto 0
Set wrdApp = wrdDoc.Application
....).
Instead I'm using:
On Error GoTo 0
Set wrdApp = wrdDoc.Application.Documents.Open
(strFileName)
The file is being opened perfectly but I'm getting the
error message "Run-time error '13': Type mismatch".

Of course it gives you a type mismatch error. You've declared wrdApp as
a Word Application object, but that line returns a Word Document object.

In any case, since the document has already been opened by
Set wrdDoc = GetObject(strFileName)
why are you trying to open it a second time?

Regards,

Alex
-----Original Message-----
Hi Alex,

The reason for the error is that you're referring to
wrdApp.Documents
before you've instantiated wrdApp.

However, if the document is already open in a running instance of Word,
Set wrdDoc = GetObject(strFileName)
should get hold of it. If it's not open, it should open it. So try
something like:

Dim strFileName as String
Dim wrdDoc As Word.Document
Dim wrdApp As Word.Application

On Error Resume Next
Set wrdDoc = GetObject(strFileName)
If wrdDoc Is Nothing then
MsgBox "COuldn't open " & strFilename
Exit Sub
End If
On Error Goto 0
Set wrdApp = wrdDoc.Application
....





On Wed, 18 Aug 2004 14:25:49 -0700, "Alex"

I'm trying to use the word document as a help file.
Before to open it, I'm checking whether it's already
opened. The checking is going fine. But, after that I get
an error message: "Object variable or With block variable
not set."

Dim MyWord As Object

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document

Dim strFileName As String, logFileIsOpened As Boolean

strFileName = "FileName"

logFileIsOpened = FileLocked(strFileName)

If logFileIsOpened = True Then

Set wrdDoc = wrdApp.Documents.Open(strFileName) ' Here
is the error !!!!!!!!!!!!!!!!!!!!!!!!!!!!
wrdDoc.Activate

Else

Set MyWord = GetObject(strFileName)
MyWord.Application.Visible = True
End If

Could anybody clarify it?

Thanks

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.
 
J

John Nurick

I'm glad it's working.

Thanks a lot again, John.
It's working now.
I've just added to your code after <Set wrdApp =
wrdDoc.Application> the following:

wrdApp.Activate
wrdApp.Visible = True

Regards,

Alex
-----Original Message-----
Comments inline.

Thanks a lot, John.
But, how could I open this file?
I'm trying to continue your code
(On Error Goto 0
Set wrdApp = wrdDoc.Application
....).
Instead I'm using:
On Error GoTo 0
Set wrdApp = wrdDoc.Application.Documents.Open
(strFileName)
The file is being opened perfectly but I'm getting the
error message "Run-time error '13': Type mismatch".

Of course it gives you a type mismatch error. You've declared wrdApp as
a Word Application object, but that line returns a Word Document object.

In any case, since the document has already been opened by
Set wrdDoc = GetObject(strFileName)
why are you trying to open it a second time?

Regards,

Alex

-----Original Message-----
Hi Alex,

The reason for the error is that you're referring to
wrdApp.Documents
before you've instantiated wrdApp.

However, if the document is already open in a running
instance of Word,
Set wrdDoc = GetObject(strFileName)
should get hold of it. If it's not open, it should open
it. So try
something like:

Dim strFileName as String
Dim wrdDoc As Word.Document
Dim wrdApp As Word.Application

On Error Resume Next
Set wrdDoc = GetObject(strFileName)
If wrdDoc Is Nothing then
MsgBox "COuldn't open " & strFilename
Exit Sub
End If
On Error Goto 0
Set wrdApp = wrdDoc.Application
....





On Wed, 18 Aug 2004 14:25:49 -0700, "Alex"

I'm trying to use the word document as a help file.
Before to open it, I'm checking whether it's already
opened. The checking is going fine. But, after that I
get
an error message: "Object variable or With block
variable
not set."

Dim MyWord As Object

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document

Dim strFileName As String, logFileIsOpened As Boolean

strFileName = "FileName"

logFileIsOpened = FileLocked(strFileName)

If logFileIsOpened = True Then

Set wrdDoc = wrdApp.Documents.Open(strFileName) '
Here
is the error !!!!!!!!!!!!!!!!!!!!!!!!!!!!
wrdDoc.Activate

Else

Set MyWord = GetObject(strFileName)
MyWord.Application.Visible = True
End If

Could anybody clarify it?

Thanks

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.
 

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