宏以导出某些Excel工作表以分隔PDF [英] Macro to Export Certain Excel Sheets to Separate PDF

查看:100
本文介绍了宏以导出某些Excel工作表以分隔PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宏,可以将工作簿中的某些图纸导出以分隔PDF(用于报告目的).它在一个工作簿中对我来说正常工作,但是在另一个工作簿中,它正在导出所有工作表.我不知道我要去哪里.为了使事情变得更容易,我在要针对其用途进行自定义的地方用斜体表示.

I have a macro to export certain sheets in a workbook to separate PDF's (for reporting purposes). It works properly for me in one workbook, however, in a different workbook it is exporting ALL sheets. I can't figure out where I am going wrong. To make things easier, I italicized the spots where I would customize it for my purposes.

Sub ExportToPDFs()  
' PDF Export Macro  
' C:\ *location*  
' Sheets(Array("*selected sheets*")).Select  

Dim nm As String  
Dim ws As Worksheet  

For Each ws In Worksheets  
ws.Select  
nm = ws.Name  

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _  
Filename:="C:\*location*" & "*Report Title*" & nm & Range("D8").Value & ".pdf", _  
Quality:=xlQualityStandard, IncludeDocProperties:=True, _  
IgnorePrintAreas:=False, OpenAfterPublish:=True  

Next ws  

End Sub

推荐答案

您需要使用要导出的工作表名称填充数组sheets_to_select.否则,这将为您工作.

You need to fill the array sheets_to_select with the names of the sheets you want this to export. Otherwise, this will work for you.

Sub ExportToPDFs()  
' PDF Export Macro  
' C:\ *location*  
' Sheets(Array("*selected sheets*")).Select  

Dim nm As String  
Dim ws As Worksheet  
Dim i as Variant, sheets_to_select as Variant

sheets_to_select = Array("Sheet1","Sheet2","Sheet3")

For Each i in sheets_to_select  
   Thisworkbook.Sheets(i).ExportAsFixedFormat Type:=xlTypePDF, _  
      Filename:="C:\*location*" & "*Report Title*" & i & Thisworkbook.Sheets("*The sheet you need the value of D8 from").Range("D8").Value & ".pdf", _  
      Quality:=xlQualityStandard, IncludeDocProperties:=True, _  
      IgnorePrintAreas:=False, OpenAfterPublish:=True  

Next i

End Sub

这篇关于宏以导出某些Excel工作表以分隔PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆