Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error '-2147417851 (80010105)'

Status
Not open for further replies.

incagold

Programmer
Mar 21, 2003
54
0
0
Morning all,

I am having difficulty opening a Word document from within a VB6 Project. The error I receive is:

Run-time error '-2147417851 (80010105)'
Automation error. The server threw an exception.

I am relatively new to VB and have searched and tried suggestions with no success. I have included the code below for your review. This activity is for a government project and the need is quite urgent. Any help that you may be able to provide would be most sincerely appreciated.

Note: wdApp is defined in an initialization module at
program start.

A variable is used for the table name as there
could be several processed by this module.

Sub ExceltoWord(strXlTbl As String)
Dim strXLFilePath As String
strXLFilePath = "C:\PCARSS_v1.0\OutputData\" & strXlTbl
'*** Open file in WORD and replace tab delimeter with |
Set wdApp = New Word.Application
wdApp.Visible = False
wdApp.Documents.Open FileName:=strXLFilePath, _
ConfirmConversions:=False, _
ReadOnly:=False, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
Revert:=False, _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
'*** Open text file and select complete document
wdApp.Selection.WholeStory
wdApp.Selection.Find.ClearFormatting
wdApp.Selection.Find.Replacement.ClearFormatting
'*** Clear any "s
With wdApp.Selection.Find
.Text = """"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdApp.Selection.Find.Execute Replace:=wdReplaceAll
'*** Clear any ?'s
With wdApp.Selection.Find
.Text = "?"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdApp.Selection.Find.Execute Replace:=wdReplaceAll
'*** Replace tab delimeter with | delimiter
With wdApp.Selection.Find
.Text = "^t"
.Replacement.Text = "|"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdApp.Selection.Find.Execute Replace:=wdReplaceAll
'*** Save document as .txt
wdApp.ActiveDocument.SaveAs FileName:=strXLFilePath, _
FileFormat:=wdFormatText, _
LockComments:=False, _
Password:="", _
AddToRecentFiles:=True, _
WritePassword:="", _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, _
SaveFormsData:=False, _
SaveAsAOCELetter:=False
wdApp.ActiveDocument.Close (wdSaveChanges)
wdApp.Application.Quit
Set wdApp = Nothing
End Sub
 
Thank you Andrzejek for your reply. Sorry for the delay, been in meetings all day.

The code gives the error at the following line:

wdApp.Documents.Open FileName:=strXLFilePath, _
ConfirmConversions:=False, _
ReadOnly:=False, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
Revert:=False, _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
 
I try to recreate your problem, but I couldn't.

I took your code and try it at my computer. It works fine.

You may Google error 2147417851, you will find many hits. Maybe that will help you.

---- Andy
 
Thanks again for your reply. I will try your suggestion. Hopefully I can find a solution. One positive thing, the code works. Now have to find out why is fails on my computeer. I sincerely appreciate your time in trying to help.
 
What versions of Word and Excel are on your machine, where it errors out, and what versions are on the machines where it doesn't?
 
Thanks Andrzejek and SBertHold for pointing me in the right direction. From seraches on the internet I found one that worked and that was to select an earlier version of the Microsoft Active X Data Objects Library. I did this and all appears to be working well. Thanks again I sincerely appreciate you taking time to help me
 

That was what I thought.
You may have then corrected it just by using late binding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top