我使用此代码将工作表导出为PDF文件。
我想添加一个代码来测试文件是否已经打开,如果是,请关闭它然后导出另一个。
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub Preview_Letter()
Application.ScreenUpdating = False
Sheet7.Visible = xlSheetVisible
Sheet7.Select
Dim File As String
File = ActiveWorkbook.Path & "\Letters\Preview.pdf"
If Not IsFileOpen(File) Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=File
Else
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=File
GoTo 1
Exit Sub
End If
1: Sheet7.Visible = xlSheetHidden
Sheet8.Activate
Sheet8.Range("A1").Select
Application.ScreenUpdating = True
ShellExecute 0, "Open", File, "", "", vbNormalNoFocus
End Sub
有没有办法关闭PDF文件(不终止Adobe Reader)??
谢谢你。