Excel批量转成PDF,只转换第一个工作表,求教!
EXCEL批量转换成PDF文档,转换是能成功,可是把两个工作表都转换成一个PDF文档了,只想把第一个工作表转换成PDF,谢谢!SubBatchConvertWorkBoo...
EXCEL批量转换成PDF文档,转换是能成功,可是把两个工作表都转换成一个PDF文档了,只想把第一个工作表转换成PDF,谢谢!
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 " & www.docin.comww.docin.comLeft(fDialog.SelectedItems(1), _
InStrRev(fDialog.SelectedItems(1), "\")), vbMaximizedFocus)
End If
End With
Set fDialog = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
我想用上面的宏把EXCEL批量转换成PDF文档,转换是能成功,可是把两个工作表都转换成一个PDF文档了,只想把第一个工作表转换成PDF,谢谢! 展开
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 " & www.docin.comww.docin.comLeft(fDialog.SelectedItems(1), _
InStrRev(fDialog.SelectedItems(1), "\")), vbMaximizedFocus)
End If
End With
Set fDialog = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
我想用上面的宏把EXCEL批量转换成PDF文档,转换是能成功,可是把两个工作表都转换成一个PDF文档了,只想把第一个工作表转换成PDF,谢谢! 展开
展开全部
这代码是你写的吧,是就好办。
你的代码核心是三句:打开文件、导出为PDF、关闭文件:
Set wkBook = Application.Workbooks.Open(vrtSelectedItem, ReadOnly:=True, Password:="")
wkBook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Left(vrtSelectedItem, InStrRev(vrtSelectedItem, ".") - 1) & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas _
:=True, OpenAfterPublish:=False
wkBook.Close , savechanges = False
在打开文件之后,增加下面的语句删除多余工作表既可达到你的目的只导出第一个表:
while wkBook.Sheets.Count>1
wkbook.Sheets(2).Delete
wend
你的代码核心是三句:打开文件、导出为PDF、关闭文件:
Set wkBook = Application.Workbooks.Open(vrtSelectedItem, ReadOnly:=True, Password:="")
wkBook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Left(vrtSelectedItem, InStrRev(vrtSelectedItem, ".") - 1) & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas _
:=True, OpenAfterPublish:=False
wkBook.Close , savechanges = False
在打开文件之后,增加下面的语句删除多余工作表既可达到你的目的只导出第一个表:
while wkBook.Sheets.Count>1
wkbook.Sheets(2).Delete
wend
追问
后面的工作表不能删除,因为第一个表的数据是从第二个工作表里读取过来的。
展开全部
wkBook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Left(vrtSelectedItem, InStrRev(vrtSelectedItem, ".") - 1) & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas _
:=True, OpenAfterPublish:=False
这是对整个工作簿进行转换的哟,改一下成为对工作表的就是了!
wkBook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Left(vrtSelectedItem, InStrRev(vrtSelectedItem, ".") - 1) & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas _
:=True, OpenAfterPublish:=False
Left(vrtSelectedItem, InStrRev(vrtSelectedItem, ".") - 1) & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas _
:=True, OpenAfterPublish:=False
这是对整个工作簿进行转换的哟,改一下成为对工作表的就是了!
wkBook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Left(vrtSelectedItem, InStrRev(vrtSelectedItem, ".") - 1) & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas _
:=True, OpenAfterPublish:=False
追问
转换过程中因为有公式和链接,会提示要不要更新,我希望是不更新,能做到吗。
追答
关闭自动更新就是了!
Application.AskToUpdateLinks = False
用完后记得打开!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不用这样吧,装个adobe acrobat就行拉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询