Hello over there,
I hope somebody from you can help me. I am trying to generate a word-document from within VB.NET and save it automatically. I've
developed a code for that, that is currently working with the Office-Versions
2003, 2007, but it fails somehow on Word2000. I didn't had an option to test it with OfficeXP yet ... I don't know why it fails and I'm not able to
figure out why.
This is the code I'm talking about - it always fails on the line
"ActiveDocument.SaveAs(strSaveFile)".
Any help? Would appreciate that very much ...
I hope somebody from you can help me. I am trying to generate a word-document from within VB.NET and save it automatically. I've
developed a code for that, that is currently working with the Office-Versions
2003, 2007, but it fails somehow on Word2000. I didn't had an option to test it with OfficeXP yet ... I don't know why it fails and I'm not able to
figure out why.
This is the code I'm talking about - it always fails on the line
"ActiveDocument.SaveAs(strSaveFile)".
Any help? Would appreciate that very much ...
VB.NET:
Public Sub Word_2000_Test()
'Create a Word App
Dim wordApp As New Microsoft.Office.Interop.Word.Application
wordApp.Visible = False
With wordApp
.Documents.Add()
Clipboard.SetText("Test-Eintrag", TextDataFormat.Text)
wordApp.Selection.InsertParagraph()
wordApp.Selection.Paste()
Dim strSaveFile As String = "C:\test.doc"
Try
If (strSaveFile <> String.Empty) And (Not (IsNothing(strSaveFile))) Then
.ActiveDocument.SaveAs(strSaveFile)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
.Visible = True
.Activate()
End With
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp)
End Sub