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
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.
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.
Red Flag This Post
Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.
Red Flag Submitted
Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.
Reply To This Thread
Posting in the Tek-Tips forums is a member-only feature.
RE: Run-time error '-2147417851 (80010105)'
Andrzejek (Programmer)Which line of your code gives you this error?
---- Andy
RE: Run-time error '-2147417851 (80010105)'
incagold (Programmer)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
RE: Run-time error '-2147417851 (80010105)'
Andrzejek (Programmer)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
RE: Run-time error '-2147417851 (80010105)'
incagold (Programmer)RE: Run-time error '-2147417851 (80010105)'
SBerthold (Programmer)RE: Run-time error '-2147417851 (80010105)'
incagold (Programmer)RE: Run-time error '-2147417851 (80010105)'
Andrzejek (Programmer)RE: Run-time error '-2147417851 (80010105)'
SBerthold (Programmer)That was what I thought.
You may have then corrected it just by using late binding.
Red Flag This Post
Red Flag Submitted
Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.
Reply To This Thread
Posting in the Tek-Tips forums is a member-only feature.
Click Here to join Tek-Tips and talk with other members! Already a Member? Login
Join Tek-Tips ® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Register now while it's still free!
Already a member? Close this window and log in.