![](/img/trans.png)
[英]Excel VBA: dynamically saving excel sheets into one PDF based on certain criteria in the cell (1 number = 1 sheet)
[英]VBA Excel saving as a PDF based on the sheet colours-Create array of sheets based on tab color
我想保存我的 PDF 文檔,盡管在指定顏色的工作表中。
我怎樣才能做到這一點?
Sub SavecolorTabtoPDF()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If Tab Color = "Blue, Accent 1, Darker 25%" Then
'export as pdf
ws.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\" & Left(ws.Name, Len(ws.Name) - 2) & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End If
Next ws
End Sub
您想遍歷工作表並根據選項卡顏色創建一組工作表。
這將創建您的工作表數組,然后將它們作為一個 pdf 格式。
Sub MakeArraySheets()
Dim sh As Worksheet
Dim ArraySheets() As String
Dim x As Variant
For Each sh In ActiveWorkbook.Worksheets
If sh.Tab.ColorIndex = 55 Then
ReDim Preserve ArraySheets(x)
ArraySheets(x) = sh.Name
x = x + 1
End If
Next sh
Sheets(ArraySheets).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & ThisWorkbook.Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
dim wsheet as worksheet
For Each wsheet In Thisworkbook.Worksheets
if wsheet.tab.colorindex = 1 then
Worksheet.SaveAs(*parameters*)
end if
next wsheet
編輯:您指定顏色的colorindex是55 。 通過用該顏色填充單元格並運行“mgbox activecell.interior.colorindex”來找出答案 EDIT2:在colorindex之前刪除了“interior”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.