|
EXCEL 2007批量转换方法
1、首先下载一个PDF转换加载项 SaveAsPDFandXPS 并安装 下载地址:http://www.microsoft.com/downloa ... 6-b059-a2e79ed87041
2、新建一个EXCEL文档 并创建如下宏:
Sub BatchConvertWorkBookToPDF()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
Dim wkBook As Workbook
Dim showFolder As Boolean
showFolder = False
With fDialog
.Filters.Add "Excel文件", "*.xls; *.xlsx; *.xlsm", 1
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
'如果选择了本工作簿则跳过
If InStrRev(vrtSelectedItem, ThisWorkbook.Name) = 0 Then
On Error Resume Next
Set wkBook = Application.Workbooks.Open(vrtSelectedItem, ReadOnly:=True, Password:="")
'跳过设置打开密码的工作簿
If Not wkBook Is Nothing Then
'跳过隐藏的工作簿
If Windows(wkBook.Name).Visible = True Then
showFolder = True
'转换开始
wkBook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Left(vrtSelectedItem, InStrRev(vrtSelectedItem, ".") - 1) & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas _
:=True, OpenAfterPublish:=False
wkBook.Close , savechanges = False
Else
wkBook.Close , savechanges = False
End If
End If
End If
Next vrtSelectedItem
If showFolder Then Call Shell("explorer.exe " & Left(fDialog.SelectedItems(1), _
InStrRev(fDialog.SelectedItems(1), "\")), vbMaximizedFocus)
End If
End With
Set fDialog = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
3、运行宏,在弹出的“浏览”对话框中选择包含要转换工作簿的文件夹,选择所有要转换的工作簿,单击“打开”按钮即可开始转换。 |
|