ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Type Mismatch Error - Help Please (https://www.excelbanter.com/excel-worksheet-functions/150890-type-mismatch-error-help-please.html)

Launchnet

Type Mismatch Error - Help Please
 
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

--
Message posted via http://www.officekb.com


John Bundy

Type Mismatch Error - Help Please
 
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.
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Launchnet" wrote:

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

--
Message posted via http://www.officekb.com



Launchnet via OfficeKB.com

Type Mismatch Error - Help Please
 
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 Bundy wrote:
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.
Hi . . .

[quoted text clipped - 64 lines]
Thanks
Matt@Launchnet


--
Please take a look at www.openoursite.com Click on: "Keywords" and then
Click on "Matt's Story" and if you are a man, you should be very happy that
you read my story. God Bless for everyones help.

Message posted via http://www.officekb.com


John Bundy

Type Mismatch Error - Help Please
 
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" wrote:

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 Bundy wrote:
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.
Hi . . .

[quoted text clipped - 64 lines]
Thanks
Matt@Launchnet


--
Please take a look at www.openoursite.com Click on: "Keywords" and then
Click on "Matt's Story" and if you are a man, you should be very happy that
you read my story. God Bless for everyones help.

Message posted via http://www.officekb.com



Launchnet via OfficeKB.com

Type Mismatch Error - Help Please
 
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 Bundy wrote:
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]
Thanks
Matt@Launchnet


--
Please take a look at www.openoursite.com Click on: "Keywords" and then
Click on "Matt's Story" and if you are a man, you should be very happy that
you read my story. God Bless for everyones help.

Message posted via http://www.officekb.com


NickHK

Type Mismatch Error - Help Please
 
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" <u20911@uwe wrote in message news:756365f5dbc08@uwe...
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 ----------------




All times are GMT +1. The time now is 11:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com