Hi,
I have a code which i suppose to print the sheets I have selected to pdf (the list of the sheetnames are in cell A1). But my code only prints blank pages (or the singled marked cells on each sheet). How do I solve this?
Here's the code:
Sub PrintSelectedSheets()
Dim wrLocal As Workbook
Dim shInput As Worksheet
Dim Sheetnames As Variant
Dim strFilename As String
Dim strFiledir As String
Dim Ans As Integer
Set wrLocal = ThisWorkbook
Set shInput = wrLocal.Worksheets("INPUT")
Sheetnames = Split(shInput.Range("A1"), ",")
Worksheets(Sheetnames).Select
strFiledir = ActiveWorkbook.Path & "\PDF"
If Right(strFiledir, 1) <> "" Then strFiledir = strFiledir & ""
strFilename = Range("filename").Value & ".pdf"
If Dir(strFiledir & strFilename) <> "" Then
Ans = MsgBox("Filename exists. Overwrite?", vbQuestion + vbYesNo, "Overwrite?")
If Ans = vbNo Then Exit Sub
End If
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFiledir & strFilename _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
Sheets("INPUT").Select
End Sub
I have a code which i suppose to print the sheets I have selected to pdf (the list of the sheetnames are in cell A1). But my code only prints blank pages (or the singled marked cells on each sheet). How do I solve this?
Here's the code:
Sub PrintSelectedSheets()
Dim wrLocal As Workbook
Dim shInput As Worksheet
Dim Sheetnames As Variant
Dim strFilename As String
Dim strFiledir As String
Dim Ans As Integer
Set wrLocal = ThisWorkbook
Set shInput = wrLocal.Worksheets("INPUT")
Sheetnames = Split(shInput.Range("A1"), ",")
Worksheets(Sheetnames).Select
strFiledir = ActiveWorkbook.Path & "\PDF"
If Right(strFiledir, 1) <> "" Then strFiledir = strFiledir & ""
strFilename = Range("filename").Value & ".pdf"
If Dir(strFiledir & strFilename) <> "" Then
Ans = MsgBox("Filename exists. Overwrite?", vbQuestion + vbYesNo, "Overwrite?")
If Ans = vbNo Then Exit Sub
End If
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFiledir & strFilename _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
Sheets("INPUT").Select
End Sub