简体   繁体   English

Document.Save 显示另存为对话框

[英]Document.Save is Showing SaveAs Dialog

I have a Visual Studio 2010 VB.NET 4.0 Windows Application project.我有一个 Visual Studio 2010 VB.NET 4.0 Windows 应用程序项目。 The code is populating a Word 2010 document.该代码正在填充 Word 2010 文档。 There are anywhere in the region of 30 to 60 tables and anywhere in the region of 30 to 50 embedded charts (all defined as inline shapes ( InlineShape )).有 30 到 60 个表的区域和 30 到 50 个嵌入图表(均定义为内联形状 ( InlineShape ))的区域。

I had to start putting in regular Document.Save() calls as I was getting the following error: There are too many edits in the document. This operation will be incomplete. Save your work.我不得不开始进行常规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. . . There is plenty of disk space available and memory also.有足够的可用磁盘空间和内存。

In most cases, the .Save() works, but randomly the save as dialog will be shown when the .Save() is called.在大多数情况下, .Save()可以工作,但在调用.Save()时会随机显示另存为对话框。 As a side note, if I click to cancel the following error is raised: Command failed at Microsoft.Office.Interop.Word.DocumentClass.Save() .作为旁注,如果我单击取消会引发以下错误: Command failed at Microsoft.Office.Interop.Word.DocumentClass.Save()

Here is an extract of the code to give you an idea of what is going on:以下是代码的摘录,让您了解正在发生的事情:

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
...

Does anybody know why the save as dialog is showing?有人知道为什么显示另存为对话框吗? Can I stop it?我能阻止吗?

Is there a reason why I am getting the "too many edits" error and therefore don't need to have so many saves going on (which is slowing the process down anyway!)?是否有原因导致我收到“编辑过多”错误,因此不需要进行如此多的保存(无论如何都会减慢进程!)?

I have been messing extensively and come up with a work around rather than a true fix.我一直在搞乱,并想出了一个解决方法而不是真正的解决方法。 I suspected that the real issue is with the too many edits error.我怀疑真正的问题是too many edits错误too many edits So I've done some more trawling and found this forum post - specifically the 4th post by Steve.所以我做了更多的搜索并找到了这个论坛帖子- 特别是史蒂夫的第 4 篇帖子。

This did the trick and I stripped it down a little to this:这确实奏效了,我将其精简为:

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 suggests that the scratch heap space has run out. Steve 建议暂存堆空间已用完。

This got rid of the too many edits in document error and subsequently I was able to remove all the doc.Save() entries - no more save as dialog showing.这摆脱了too many edits in document错误中的too many edits in document ,随后我能够删除所有doc.Save()条目 - 不再显示保存为对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM