incagold
Programmer
- Mar 21, 2003
- 54
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
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