我有一些代碼在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