Sub SheetstoPdf()
'ExcelDemy product
Dim Sheet1Name As String
Dim Sheet2Name As String
Sheet1Name = "Sheet2"
Sheet2Name = "Sheet3"
If Worksheets(Sheet1Name).Range("D7") = Worksheets(Sheet2Name).Range("B7") Then
Sheets(Array(Sheet1Name, Sheet1Name)).Select
Sheets(Sheet1Name).Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Sheet1Name & " And " & Sheet2Name, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
If Worksheets(Sheet1Name).Range("B7") = Worksheets(Sheet2Name).Range("B7") Then
Sheets(Sheet1Name).Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Sheet1Name, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Sheets(Sheet2Name).Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Sheet2Name, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
For i = 2 To 80
matched = 0
Sheet1Name = "Sheet" & i
Sheet2Name = "Sheet" & Right(Str(i + 1), Len(Str(i + 1)) - 1)
If Worksheets(Sheet1Name).Range("D7") = Worksheets(Sheet2Name).Range("B7") Then
Sheets(Array(Sheet1Name, Sheet2Name)).Select
Sheets(Sheet1Name).Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Sheet1Name & " And " & Sheet2Name, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
matched = matched + 1
End If
If Worksheets(Sheet1Name).Range("B7") = Worksheets(Sheet2Name).Range("B7") Then
Sheets(Sheet1Name).Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Sheet1Name, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Sheets(Sheet2Name).Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Sheet2Name, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
matched = matched + 1
End If
If matched > 0 Then
Exit For
End If
Next i
End Sub