• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Macro to allow user to Save as PDF and Print out |VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Macro to allow user to Save as PDF and Print out |VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosMacro to allow user to Save as PDF …
sp_PrintTopic sp_TopicIcon
Macro to allow user to Save as PDF and Print out
Avatar
Training Wheels...

New Member
Members
Level 0
Forum Posts: 2
Member Since:
November 14, 2019
sp_UserOfflineSmall Offline
1
November 14, 2019 - 8:07 am
sp_Permalink sp_Print

Hi all,

Not only am I new to the macro world, my macros are still at the recording stage...so bear with me please...

After trying for 2 days to complete my macros with the recorder, with no success, I am going crazy. I need your help to do the following please..!.

 

My workbook has two worksheets that I need to user to be able to Save as a PDF with a fixed name and Print out (assuming they have a printer connected...).

The first worksheet is called "BANK ACCOUNT" and is text, in a fixed range that needs to be Saved and Printed.

The second worksheet is called "Schedules" and has 3 tables that need to be filtered (remove 0), Saved, Printed, and then refiltered back to their original state (Select all).

Reading thru the threads here, I've tried using some parts from past solutions but I think the combination of "clean code" with my recorded code is just making it worse....

Any help greatly greatly appreciated.

Thank you.

 

I've posted my latest attempts on the 4 separate macros below...

 

 

Sub Xbankprint()
'
' Xbankprint Macro
'

Sheets("BANK ACCOUNT").Visible = True
Range("B3:F10").Select
Sheets("Dashboard").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
ActiveWindow.SelectedSheets.Visible = False
Range("B3:F43").Select
Selection.PrintOut Copies:=1, Collate:=True
Range("B3:F10").Select
Sheets("Dashboard").Visible = True
Sheets("Summary").Visible = True
Range("K6:O8").Select
Sheets("BANK ACCOUNT").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
Range("A1:W45").Select
ActiveWindow.Zoom = True
Range("K6:O8").Select
End Sub

 

Sub Xbanksave()
'
' Xbanksave Macro
'

Sheets("BANK ACCOUNT").Visible = True
Range("B3:F10").Select
Sheets("Dashboard").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
ActiveWindow.SelectedSheets.Visible = False
Range("B3:F43").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Range("B3:F10").Select
Sheets("Dashboard").Visible = True
Sheets("Summary").Visible = True
Range("K6:O8").Select
Sheets("BANK ACCOUNT").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
Range("A1:W45").Select
ActiveWindow.Zoom = True
Range("K6:O8").Select

End Sub

 

Sub Xscheduleprint()
'
' Xscheduleprint Macro
'

Sheets("Schedules").Visible = True
Sheets("Dashboard").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Schedules").Select
Range("BILLS[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("BILLS").Range.AutoFilter Field:=3, Criteria1:= _
Array("$115", "$120", "$140", "$240", "$30", "$40", "$400", "$50", "$58", "$59", "$60", _
"$70"), Operator:=xlFilterValues
ActiveWindow.SmallScroll Down:=40
Range("DEBIT[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("DEBIT").Range.AutoFilter Field:=3, Criteria1:= _
Array("$150", "$180", "$2", "$30"), Operator:=xlFilterValues
Range("CREDIT[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("CREDIT").Range.AutoFilter Field:=3, Criteria1:= _
Array("$100", "$200", "$400", "$800"), Operator:=xlFilterValues
ActiveWindow.SmallScroll Down:=-40
ActiveWindow.SmallScroll ToRight:=-2
Range("BT85:CB230").Select
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$B$2:$F$57"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.236220472440945)
.RightMargin = Application.InchesToPoints(0.236220472440945)
.TopMargin = Application.InchesToPoints(0.748031496062992)
.BottomMargin = Application.InchesToPoints(0.748031496062992)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 2
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Selection.PrintOut Copies:=1, Collate:=True
Range("CREDIT[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("CREDIT").Range.AutoFilter Field:=3
ActiveWindow.SmallScroll Down:=-24
Range("DEBIT[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("DEBIT").Range.AutoFilter Field:=3
ActiveWindow.SmallScroll Down:=-48
Range("BILLS[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("BILLS").Range.AutoFilter Field:=3
ActiveWindow.SmallScroll Down:=-16
ActiveWindow.SmallScroll ToRight:=-2
Range("BT85:BW85").Select
Sheets("Dashboard").Visible = True
Sheets("Summary").Visible = True
Sheets("Schedules").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
Range("A1:V45").Select
ActiveWindow.Zoom = True
Range("K6:O8").Select
End Sub

 

Sub Xschedulesave()
'
' Xschedulesave Macro
'

Sheets("Schedules").Visible = True
Sheets("Dashboard").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
ActiveWindow.SelectedSheets.Visible = False
Range("BILLS[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("BILLS").Range.AutoFilter Field:=3, Criteria1:= _
Array("$115", "$120", "$140", "$240", "$30", "$40", "$400", "$50", "$58", "$59", "$60", _
"$70"), Operator:=xlFilterValues
ActiveWindow.SmallScroll Down:=48
Range("DEBIT[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("DEBIT").Range.AutoFilter Field:=3, Criteria1:= _
Array("$150", "$180", "$2", "$30"), Operator:=xlFilterValues
ActiveWindow.SmallScroll Down:=8
Range("CREDIT[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("CREDIT").Range.AutoFilter Field:=3, Criteria1:= _
Array("$100", "$200", "$400", "$800"), Operator:=xlFilterValues
ActiveWindow.SmallScroll Down:=-48
Range("BT85:CB230").Select
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$B$2:$F$57"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.236220472440945)
.RightMargin = Application.InchesToPoints(0.236220472440945)
.TopMargin = Application.InchesToPoints(0.748031496062992)
.BottomMargin = Application.InchesToPoints(0.748031496062992)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 2
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With

ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=OpenPDFAfterCreating
Range("CREDIT[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("CREDIT").Range.AutoFilter Field:=3
ActiveWindow.SmallScroll Down:=-24
Range("DEBIT[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("DEBIT").Range.AutoFilter Field:=3
ActiveWindow.SmallScroll Down:=-48
Range("BILLS[[#Headers],[Amount]]").Select
ActiveSheet.ListObjects("BILLS").Range.AutoFilter Field:=3
ActiveWindow.SmallScroll Down:=-32
ActiveWindow.SmallScroll ToRight:=-3
Range("BT85:BW85").Select
ActiveWindow.SmallScroll Down:=27
Sheets("Dashboard").Visible = True
Sheets("Summary").Visible = True
Sheets("Schedules").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Summary").Select
Range("A1:V45").Select
ActiveWindow.Zoom = True
Range("K6:O8").Select
End Sub

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1845
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
November 16, 2019 - 1:59 pm
sp_Permalink sp_Print

Try this code:

Sub Macro1()
Dim Tbl As ListObject

Set Tbl = ThisWorkbook.Worksheets("Schedules").ListObjects("BILLS")
Tbl.Range.AutoFilter Field:=Tbl.ListColumns("Amount").Index, Criteria1:="<>0", Operator:=xlAnd
Tbl.Range.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Catalin\Desktop\Bills.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
Tbl.Range.AutoFilter Field:=Tbl.ListColumns("Amount").Index

Set Tbl = ThisWorkbook.Worksheets("Schedules").ListObjects("CREDIT")
Tbl.Range.AutoFilter Field:=Tbl.ListColumns("Amount").Index, Criteria1:="<>0", Operator:=xlAnd
Tbl.Range.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Catalin\Desktop\CREDIT.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
Tbl.Range.AutoFilter Field:=Tbl.ListColumns("Amount").Index

Set Tbl = ThisWorkbook.Worksheets("Schedules").ListObjects("DEBIT")
Tbl.Range.AutoFilter Field:=Tbl.ListColumns("Amount").Index, Criteria1:="<>0", Operator:=xlAnd
Tbl.Range.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Catalin\Desktop\DEBIT.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
Tbl.Range.AutoFilter Field:=Tbl.ListColumns("Amount").Index

ThisWorkbook.Worksheets("Bank Account").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Catalin\Desktop\Book1.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
Set Tbl = Nothing
End Sub

sp_AnswersTopicAnswer
Answers Post
Avatar
Training Wheels...

New Member
Members
Level 0
Forum Posts: 2
Member Since:
November 14, 2019
sp_UserOfflineSmall Offline
3
November 16, 2019 - 8:30 pm
sp_Permalink sp_Print

Thx mate!,

I know it was probably a simple thing for you but it means alot to me.

I'll study it and learn from it also.

Again, Thank you!

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Sameh Alami, Peter Wilden, Donnacha Holly, Ineke Smit
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
Hans Hallebeek: 188
Newest Members:
JUDY MLL
Scot Bailey
Kate Dyka
Kwaje Alfred Mogga
thong nguyen
Appiagyei Kofi Frimpong
Hilary Burchfield
Richie Wright
Adel Kock
Barbara Murray
Forum Stats:
Groups: 3
Forums: 24
Topics: 6548
Posts: 28672

 

Member Stats:
Guest Posters: 49
Members: 32834
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.