语境:
vb.net 程序
Visual Studio 2010 终极版
MS Word 2010 自动化
Microsoft.Office.Interop.Word 库
我正在使用 saveAs2 方法来保存我正在创建的新文档,但是当我调用该方法时应用程序仍在提示我。为什么?
应用程序不可见。application.displayAlerts 为假
有什么想法吗?
此外,当我手动完成 SaveUI 提示时,saveAs2 方法会引发异常。
这是我为要求它的人提供的代码:
Public Sub generateModel() Implements ModelGenerator.generateModel
wordApp.Visible = True
wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
wordDoc = wordApp.Documents.Add
wordDoc.PageSetup.TopMargin = wordApp.InchesToPoints(0.25)
wordDoc.PageSetup.BottomMargin = wordApp.InchesToPoints(0.25)
wordDoc.PageSetup.LeftMargin = wordApp.InchesToPoints(0.25)
wordDoc.PageSetup.RightMargin = wordApp.InchesToPoints(0.25)
With wordDoc.Content.Paragraphs.Add(wordDoc.Bookmarks.Item("\endofdoc").Range)
.Range.Text = _text
.Format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
.Format.LineUnitBefore = 1
.Range.Font.SmallCaps = True
.Range.Font.Size = 12
End With
Dim logo = wordDoc.Shapes.AddPicture(logoLoc)
logo.Height = wordApp.InchesToPoints(0.5)
logo.Width = wordApp.InchesToPoints(1.18)
Me.mainTable = wordDoc.Tables.Add(wordDoc.Bookmarks.Item("\endofdoc").Range, 3, 2)
mainTable.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightExactly
mainTable.Columns.Width = wordApp.InchesToPoints(4)
mainTable.Rows.Height = wordApp.InchesToPoints(3.25)
mainTable.Select()
wordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
With wordDoc.Content.Paragraphs.Add(wordDoc.Bookmarks.Item("\endofdoc").Range)
.Range.Text = "Rapport journalier de production - page 2"
.Range.Font.Size = 10
.Format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
.Format.LineUnitBefore = 0
.Format.SpaceBeforeAuto = False
.Format.SpaceBefore = 0
End With
wordDoc.SaveAs2("C:\Doc1.docx")
wordDoc.Close(False)
wordApp.Application.Quit()
End Sub
**更新:
我在另一台机器上测试了代码,它可以工作。所以我在我的身上尝试了这段代码:
Dim app As New Microsoft.Office.Interop.Word.Application
Dim doc = app.Documents.Add
doc.SaveAs2("C:\Users\simon\Documents\Doc3.docx")
它仍然使 saveUI 弹出。我很混乱...