问题描述:

I'm programming a Microsoft Word plugin in VB.Net, and I have a code that calls a function to save the document as PDF (Office 2007).

I use two functions:

Public Sub SaveLandscape_CallBack(ByVal Control As Office.IRibbonControl)

SaveEbook(True)

End Sub

And

Public Sub SaveEbook(ByVal ForceLandscape As Boolean)

Try

Dim FilePath As String = Globals.ThisAddIn.Application.ActiveDocument.Path & "\" & Globals.ThisAddIn.Application.ActiveDocument.Name & ".ebook.pdf"

Try

Globals.ThisAddIn.Application.ActiveDocument.ExportAsFixedFormat(OutputFileName:=FilePath, ExportFormat:=Word.WdExportFormat.wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Range:=Word.WdExportRange.wdExportAllDocument, Item:=Word.WdExportItem.wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=Word.WdExportCreateBookmarks.wdExportCreateHeadingBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=True)

Catch ex As Exception

MsgBox(ex.ToString)

End Try

Catch Ex As Exception

MsgBox(Ex.ToString)

End Try

I've trimmed the second one a lot, which is why there is this unused parameter.

The first function is associated to a ribbon button. Every time I run it, ExportAsFixedFormat returns an error saying the file is in use, whatever name I use.

Any idea?

Thanks,

CFP.

EDIT: I've identified the problem to be exactly the same as http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/95c5b101-0d98-49f8-a92b-7b444e61cca8/ . Any ideas anyone?

网友答案:

Try putting Globals.ThisAddIn.Application.ActiveDocument.Saved = True before the Globals... line.

相关阅读:
Top