1
我需要自动化一些过程。我写了一些代码将PDF文件发布为PDF格式:Coreldraw VBA GlobalMacroStorage:如何在打开后关闭活动文档?
Sub GlobalMacroStorage_DocumentOpen(ByVal doc As Document, ByVal FileName As String)
Set doc = ActiveDocument
With doc.PDFSettings
...{some code here}
.Linearize = True
.PageRange = "1,2"
.pdfVersion = pdfVersion13
.PublishRange = pdfPageRange
.TrueTypeToType1 = True
.TextAsCurves = True
.OverprintBlackLimit = True
End With
If Len(Dir(doc.FilePath + "\coreltmp", vbDirectory)) = 0 Then
MkDir doc.FilePath + "coreltmp"
End If
name2 = Dir(FileName) + "TEST.pdf"
strName = doc.FilePath & "coreltmp" & "\" & name2
doc.PublishToPDF strName
ActiveDocument.Close <<=====ERROR LINE
End Sub
标记行出错:文档无法从文档事件处理程序中关闭。所以问题是:如果没有完整的应用程序,这个文件有多接近?
它可能是,你正试图关闭该文件之前完成处理PDF。尝试在ActiveDocument.Close << =====错误行之前放置一个消息框,并等待5或10秒钟关闭它。这应该创建一个单独的线程,并有足够的时间来处理PDF。如果你没有得到这个错误,那就是这个问题。 – PractLogical
我将此宏的PDF_publish代码移除到另一个:“pdf_exporter”。现在在这个宏中我有“打电话pdf_exporter”。当我手动运行它时,它可以工作,但是在自动模式下PDF创建正常,但它不关闭文档(它的工作原理没有错误信息,一切正常,但文档仍然打开) –
打开时,您想关闭文档?这不会使文档无法打开吗? – Yakk