[英]Document.Save is Showing SaveAs Dialog
我有一個 Visual Studio 2010 VB.NET 4.0 Windows 應用程序項目。 該代碼正在填充 Word 2010 文檔。 有 30 到 60 個表的區域和 30 到 50 個嵌入圖表(均定義為內聯形狀 ( InlineShape
))的區域。
我不得不開始進行常規Document.Save()
調用,因為我收到以下錯誤: There are too many edits in the document. This operation will be incomplete. Save your work.
There are too many edits in the document. This operation will be incomplete. Save your work.
. 有足夠的可用磁盤空間和內存。
在大多數情況下, .Save()
可以工作,但在調用.Save()
時會隨機顯示另存為對話框。 作為旁注,如果我單擊取消會引發以下錯誤: Command failed at Microsoft.Office.Interop.Word.DocumentClass.Save()
。
以下是代碼的摘錄,讓您了解正在發生的事情:
Imports _word = Microsoft.Office.Interop.Word
...
...
Dim wrd As _word.Application = CreateObject("Word.Application")
wrd.Visible = True
wrd.ScreenUpdating = True
Dim doc As _word.Document = wrd.Documents.Open("C:\my-file-template.docx")
doc.Application.DisplayAlerts = _word.WdAlertLevel.wdAlertsNone
doc.Range.NoProofing = True
Dim reportFilePathName As String = "C:\my-file.docx"
If File.Exists(reportFilePathName) Then
File.Delete(Me.reportFilePathName)
End If
doc.SaveAs2(reportFilePathName)
...
'Numerous tasks carried out
...
doc.Save() 'This may or may not cause the save as dialog to show
...
有人知道為什么顯示另存為對話框嗎? 我能阻止嗎?
是否有原因導致我收到“編輯過多”錯誤,因此不需要進行如此多的保存(無論如何都會減慢進程!)?
我一直在搞亂,並想出了一個解決方法而不是真正的解決方法。 我懷疑真正的問題是too many edits
錯誤too many edits
。 所以我做了更多的搜索並找到了這個論壇帖子- 特別是史蒂夫的第 4 篇帖子。
這確實奏效了,我將其精簡為:
Imports _word = Microsoft.Office.Interop.Word
...
Public Shared Sub GarbageCollect(ByRef doc As _word.Document)
doc.Application.Options.Pagination = False
doc.UndoClear()
doc.Repaginate()
doc.Application.ScreenUpdating = True
doc.Application.ScreenRefresh()
End Sub
Steve 建議暫存堆空間已用完。
這擺脫了too many edits in document
錯誤中的too many edits in document
,隨后我能夠刪除所有doc.Save()
條目 - 不再顯示保存為對話框。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.