我有一些代码在Word文件中插入多个图像。一切都很好 直到我试图保存文件,于是它给出了这样的错误:保存Word文档 - 错误
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in pdf1.exe
Additional information: This filename is incorrect.
Try one or more of the following:
Probe the track to make sure it is typed correctly.
Select a file from the list of files and folders.
,这是代码:
' first we are creating application of word.
Dim WordApp As New Microsoft.Office.Interop.Word.Application()
' now creating new document.
WordApp.Documents.Add()
' see word file behind your program
WordApp.Visible = True
' get the reference of active document
Dim doc As Microsoft.Office.Interop.Word.Document = WordApp.ActiveDocument
' set openfiledialog to select multiple image files
Dim ofd As New OpenFileDialog()
ofd.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF"
ofd.Title = "Select Image To Insert...."
ofd.Multiselect = True
' if user select OK, then process for adding images
If ofd.ShowDialog() = DialogResult.OK Then
' iterating process for adding all images which is selected by filedialog
For Each filename As String In ofd.FileNames
' now add the picture in active document reference
doc.InlineShapes.AddPicture(filename, Type.Missing, Type.Missing, Type.Missing)
Next
End If
' file is saved.
doc.SaveAs("E:\Doc8.docx", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing)
' application is now quit.
WordApp.Quit(Type.Missing, Type.Missing, Type.Missing)
在VB中,我们不必包含'Type.Missing'。 – OneFineDay