Run Time Error 4198

Vorag

New Member
Joined
Apr 11, 2011
Messages
4
I am encountering the following run-time error when lauching the code below from an Active X command button in Excel 2010, launching Word 2010. I have a spreadsheet which has the option to load a word doc which is a helpfile. This code was working fine, but will not now and I can't determine why. It fails on the 'open' line. I have checked the server and document path and they are still correct. Apprectiate any help on this one, Cheers V.

Rich (BB code):
 sub launchhelpfile()
Set wordapp = CreateObject("word.Application")
        wordapp.documents.Open "\\Porter\AMGRTREAT\Asset Management\Asset Management Plans\2011\Editing Master Asset Plans to refer to site specific.doc"
        wordapp.Visible = True
        Set wordapp = Nothing 
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the Forum,

Do you have Option Explict in the Module at the top if so delete it. That maybe the cause as you aren't declaring wordapp.
 
Upvote 0
Hi, thanks Trevor for the response (like the BCFC pic). I don't have option explicit - though did have it set in a private sub. Tried declaring it Dim wordapp As Object and tried it as a sub(), but encountered the same 4198 error.
Can't understand why this no longer works as it was opening the doc correctly. If I move the wordapp.visible line above the .open line it will initialise and display word (2010), but then won't open the document. I have also tried saving the file as a docx and amending the path.
 
Upvote 0
I have just tested the following and it opens OK, I have used a different path of course though.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> launchhelpfile()<br><SPAN style="color:#00007F">Dim</SPAN> wrdApp <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wrdApp = CreateObject("word.Application")<br><br>       wrdApp.documents.Open "\\Porter\AMGRTREAT\Asset Management\Asset Management Plans\2011\Editing Master Asset Plans to refer to site specific.doc"<br>        wrdApp.Visible = <SPAN style="color:#00007F">True</SPAN><br>        <SPAN style="color:#00007F">Set</SPAN> wrdApp = <SPAN style="color:#00007F">Nothing</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Have tested again, stepping through the code with F8 and it runs, yet when I try to run from the command button it errors.
When stepping through and having opened the word file, I close it down, it informs me that the Normal.dotm template has been modified, would I like to save changes? I'm presuming that my word file must still be open in the background somewhere and when I am trying to execute the code it is showing that the file is read-locked?
This error is commonly encountered when a read lock is set on the file that you are attempting to open. Possible reasons for this:
<DIR>Another user has the file open, either on the same computer that you are using, or on another computer.
Word crashed at some point in the past and left a read lock on the file.
Another application has an exclusive lock on the file, preventing Word from opening the file.
A custom application is running and has opened this file (possibly on another user's computer). It may have opened the file using an incorrect method.
</DIR>
 
Upvote 0
It appears that when testing my code I had made some error and had 5 or 6 versions of word open in the background which were not visible and had locked the file. I have just shut them down and tested with the original file path and it works. Thank you for the help.
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,420
Members
452,325
Latest member
BlahQz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top