【发布时间】:2014-11-01 02:54:34
【问题描述】:
我使用此代码从 word 文档中导出 pdf 文件。
在导出之前,我需要先检查一个同名文件是否已经打开,如果是,请关闭它然后导出。
我尝试了很多东西,但都没有运气。
Dim adbApp As Acrobat.AcroApp
Dim adbDoc As Acrobat.AcroAVDoc
Dim adbPageView As Acrobat.AcroAVPageView
Set adbApp = CreateObject("AcroExch.App")
Set adbDoc = CreateObject("AcroExch.AVDoc")
If adbDoc.Open("C:\Current Letter Preview.pdf", "") = True Then '==> If the file is not open, this line opens it
adbDoc.Close (1) '==> Then close it
If adbDoc Is Nothing Then '==> Doesn't understand that I want to check if any pdf files are open
adbApp.Exit
End If
Set adbApp = Nothing
End If
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
If IsFileOpen("C:\TemporaryLetter.docx") Then
Set wordApp = GetObject(, "Word.Application")
wordApp.Documents("C:\TemporaryLetter.docx").Close '==> Is there something like that regarding acrobat IAC?
Else
Set wordApp = CreateObject("Word.Application")
With wordApp
.Visible = True
.WindowState = 2
End With
End If
Set wordDoc = wordApp.Documents.Open("C:\TemporaryLetter.docx")
wordDoc.ExportAsFixedFormat OutputFileName:="C:\Current Letter Preview.pdf", _
ExportFormat:=wdExportFormatPDF
wordDoc.Close savechanges:=wdDoNotSaveChanges
Set wordDoc = Nothing
If wordDoc Is Nothing Then
wordApp.Quit
End If
Set wordApp = Nothing
Call adbDoc.Open("C:\Current Letter Preview.pdf", "")
adbDoc.BringToFront
Set adbPageView = adbDoc.GetAVPageView()
Call adbPageView.ZoomTo(0, 100)
Set adbDoc = Nothing
Set adbPageView = Nothing
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。