Type Mismatch Error - Help Please

L

Launchnet

Hi . . .

The all CAPS area states what the problem is. Can someone help please.

Sub NewWordWithDocument()
Dim oWordApp As Object
Dim oWordDoc As Object
Set oWordApp = CreateObject("Word.Application")
' oWordApp.Visible = True
' Set oWordDoc = oWordApp.Documents.Open( _
' "C:\documents and settings\default\my documents\CompClassChurchBulletin.
doc")

'WITH THE PATH AND DOCUMENT HARD CODED AS ABOVE, IT WORKED, BUT HAD NO
TESTING.

'FROM HERE DOWN THE TESTING WORKS FINE.
'THEN, WHEN IT GETS TO THE LAST LINE OF CODE WHICH IS TO OPEN THE FILE
IN THE ACTIVECELL.
'AN ERROR MESSAGE IS DISPLAYED: "Type Mismatch"
'I CLICK DEBUG AND THE LAST LINE OF CODE IS HIGHLITED IN YELLOW.
'I DON'T KNOW WHAT I DID WRONG.




Dim testFileFind
Dim oWB As Object

ActiveCell.Offset(0, -1).Activate 'this moves the selected cell 1 cell to
the Left

'The following tests for a blank cell and ends processing
'It is needed because dir() function will not work with a blank.

If Len(Trim(ActiveCell)) = 0 Then
MsgBox "Active Cell " & ActiveCell.Address & " is blank. You have not
entered a Path & File Name."
End
End If

'The following tests for the existance of the file

testFileFind = Dir(ActiveCell)

'If the file is not found there will be nothing
'in the variable and processing ends.

If Len(testFileFind) = 0 Then
MsgBox "Invalid selection." & Chr(13) & _
"Filename " & ActiveCell & " not found"
End
End If

'THIS LINE OF CODE OPENS THE NEW INSTANCE OF WORD.
Set oWordApp = CreateObject("Word.Application")

'THIS LINE OF CODE MAKES THE NEW INSTANCE OF WORD VISIBLE.
oWordApp.Visible = True

Set oWordDoc = oWordApp.Documents.Open(ActiveCell)

End Sub


Can someone find the "Type Mismatch" whatever that means.

Thanks
Matt@Launchnet
 
J

John Bundy

The problem really has to be the string in Activecell, ensure that it is
correct, post it if you are not sure. Easy way to test is to change the name
of the file to like 123 and make sure it works.
 
L

Launchnet via OfficeKB.com

Thanks . . .
I have tried numerous paths & files and they all do the same thing. I have
the code for doing this in Excel, opening and Excel file and it works fine.

Any other ideas. Maybe it has to do with the object.

John said:
The problem really has to be the string in Activecell, ensure that it is
correct, post it if you are not sure. Easy way to test is to change the name
of the file to like 123 and make sure it works.
[quoted text clipped - 64 lines]
Thanks
Matt@Launchnet
 
J

John Bundy

DOH!! Tried it again and it didn't work, activecell.text did
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


Launchnet via OfficeKB.com said:
Thanks . . .
I have tried numerous paths & files and they all do the same thing. I have
the code for doing this in Excel, opening and Excel file and it works fine.

Any other ideas. Maybe it has to do with the object.

John said:
The problem really has to be the string in Activecell, ensure that it is
correct, post it if you are not sure. Easy way to test is to change the name
of the file to like 123 and make sure it works.
[quoted text clipped - 64 lines]
Thanks
Matt@Launchnet
 
L

Launchnet via OfficeKB.com

Hi John . . .
Just a WORD of Thanks. I tested it and it seems to work fine.
I will give it a very good test just to be sure.
Many thanks again.
Matt@Launchnet

John said:
DOH!! Tried it again and it didn't work, activecell.text did
Thanks . . .
I have tried numerous paths & files and they all do the same thing. I have
[quoted text clipped - 10 lines]
 
N

NickHK

I think we discussed these SpecialFolders before.
On my system there is no such path as "C:\documents and settings\default\my
documents\.."
It is "C:\Documents and Settings\Default User\My Documents\...

Depending on how you are getting/setting this path, it may not work on all
systems.

NickHK

Launchnet said:
Hi . . .

The all CAPS area states what the problem is. Can someone help please.

Sub NewWordWithDocument()
Dim oWordApp As Object
Dim oWordDoc As Object
Set oWordApp = CreateObject("Word.Application")
' oWordApp.Visible = True
' Set oWordDoc = oWordApp.Documents.Open( _
' "C:\documents and settings\default\my documents\CompClassChurchBulletin.
doc")
---------- CUT ----------------
 

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