Home

Macro to print double sided

%3CLINGO-SUB%20id%3D%22lingo-sub-699032%22%20slang%3D%22en-US%22%3EMacro%20to%20print%20double%20sided%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-699032%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20created%20the%20attached%20spreadsheet%20and%20inserted%20the%20basic%20macro%20where%20it%20will%20print%20multiple%20sheets%20from%20and%20to%20the%20date%20range%20I%20specify%20in%20the%20macro.%20This%20is%20to%20act%20as%20a%20register%20and%20saves%20times%20copying%20and%20pasting%20the%20date%20each%20and%20every%20time.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20issue%20I%20am%20having%20is%20the%20sheets%20will%20not%20print%20duplex%20no%20matter%20what%20I%20do.%20I%20have%20tried%20changing%20the%20default%20printer%20and%20even%20put%20code%20in%20to%20select%20the%20printer%20before%20it%20prints%20the%20sheets.%20In%20setup%20duplex%20is%20selected%20but%20still%20comes%20out%20as%20single%20sheets.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anyone%20have%20an%20idea%20whats%20wrong%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20alternative%20is%20to%20change%20the%20macro%20so%20it%20does%20the%20same%20thing%20but%20instead%20prints%20all%20sheets%20into%20one%20PDF%20file.%20From%20there%20I%20can%20print%20however%20I%20do%20not%20know%20how%20to%20write%20this%20code%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-699032%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-699176%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20to%20print%20double%20sided%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-699176%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F275880%22%20target%3D%22_blank%22%3E%40az123330%3C%2FA%3E%26nbsp%3B%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3EThe%20problem%20is%20that%20your%20macro%20sends%20out%20a%20new%20printcommand%20for%20each%20date%2C%20which%20the%20printer%20then%20immediately%20processes.%20If%20the%20sheet%20would%20be%20larger%20so%20there%20are%20two%20pages%20to%20print%2C%20I%20bet%20those%20would%20be%20printed%20in%20duplex.%20Here%20is%20a%20macro%20that%20appears%20to%20do%20the%20trick.%20It%20creates%20temporary%20copies%20of%20the%20worksheet%2C%20enters%20the%20date%20into%20them%20and%20then%20prints%20all%20of%20them%20in%20one%20go%20and%20subsequently%20deletes%20the%20copies%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CPRE%3ESub%20PrintAllDates()%0A%20%20%20%20Dim%20vSheets()%20As%20Variant%0A%20%20%20%20Dim%20printDate%20As%20Date%0A%20%20%20%20Dim%20startDate%20As%20Date%0A%20%20%20%20Dim%20endDate%20As%20Date%0A%20%20%20%20Dim%20lShtCt%20As%20Long%0A%20%20%20%20ReDim%20vSheets(1%20To%201)%0A%20%20%20%20Application.Dialogs(xlDialogPrinterSetup).Show%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20startDate%20%3D%20%2218%2F06%2F19%22%0A%20%20%20%20endDate%20%3D%20%2219%2F06%2F19%22%0A%20%20%20%20For%20printDate%20%3D%20startDate%20To%20endDate%0A%20%20%20%20%20%20%20%20ActiveSheet.Range(%22C1%22)%20%3D%20printDate%0A%20%20%20%20%20%20%20%20lShtCt%20%3D%20lShtCt%20%2B%201%0A%20%20%20%20%20%20%20%20ReDim%20Preserve%20vSheets(1%20To%20lShtCt)%0A%20%20%20%20%20%20%20%20vSheets(lShtCt)%20%3D%20ActiveSheet.Name%0A%20%20%20%20%20%20%20%20ActiveSheet.Copy%20ActiveSheet%0A%20%20%20%20Next%0A%20%20%20%20Application.DisplayAlerts%20%3D%20False%0A%20%20%20%20ActiveSheet.Delete%0A%20%20%20%20Application.DisplayAlerts%20%3D%20True%0A%20%20%20%20Sheets(vSheets).Select%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20ActiveWindow.SelectedSheets.PrintOut%0A%20%20%20%20'New%20delete%20the%20temporary%20sheets%0A%20%20%20%20'%20Make%20a%20list%20of%20them%20by%20removing%20the%20first%20sheet%20from%20the%20list%20(since%20that%20is%20our%20original)%0A%20%20%20%20For%20lShtCt%20%3D%20LBound(vSheets)%20To%20UBound(vSheets)%20-%201%0A%20%20%20%20%20%20%20%20vSheets(lShtCt)%20%3D%20vSheets(lShtCt%20%2B%201)%0A%20%20%20%20Next%0A%20%20%20%20ReDim%20Preserve%20vSheets(1%20To%20lShtCt%20-%201)%0A%20%20%20%20'Now%20delete%0A%20%20%20%20Sheets(vSheets).Select%0A%20%20%20%20Application.DisplayAlerts%20%3D%20False%0A%20%20%20%20ActiveWindow.SelectedSheets.Delete%0A%20%20%20%20Application.DisplayAlerts%20%3D%20True%0AEnd%20Sub%0A%3C%2FPRE%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-699227%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20to%20print%20double%20sided%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-699227%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThats%20fantastic!%20I%20really%20need%20to%20learn%20how%20to%20code%20on%20this.%20Works%20exactly%20as%20intended.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20bit%20of%20an%20out%20the%20box%20question%20but%20do%20you%20know%20if%20I%20can%20somehow%20have%20it%20so%20it%20skips%20weekends%20throughout%20the%20year%3F%20The%20register%20is%20only%20meant%20for%20Mon-Fri%20and%20since%20its%20double%20sided%20I%20can't%20just%20get%20rid%20of%20the%20weekends%20because%20they%20end%20up%20printing%20on%20the%20same%20page%20as%20the%20weekdays.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-699479%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20to%20print%20double%20sided%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-699479%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F275880%22%20target%3D%22_blank%22%3E%40az123330%3C%2FA%3E%20You%20can%20omit%20weekends%20like%20so%3A%3C%2FP%3E%0A%3CPRE%3ESub%20PrintAllDates()%0A%20%20%20%20Dim%20vSheets()%20As%20Variant%0A%20%20%20%20Dim%20printDate%20As%20Date%0A%20%20%20%20Dim%20startDate%20As%20Date%0A%20%20%20%20Dim%20endDate%20As%20Date%0A%20%20%20%20Dim%20lShtCt%20As%20Long%0A%20%20%20%20ReDim%20vSheets(1%20To%201)%0A%20%20%20%20Application.Dialogs(xlDialogPrinterSetup).Show%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20startDate%20%3D%20%2215%2F06%2F19%22%0A%20%20%20%20endDate%20%3D%20%2219%2F06%2F19%22%0A%20%20%20%20For%20printDate%20%3D%20startDate%20To%20endDate%0A%20%20%20%20%20%20%20%20If%20Weekday(printDate%2C%20vbMonday)%20%26lt%3B%206%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20ActiveSheet.Range(%22C1%22)%20%3D%20printDate%0A%20%20%20%20%20%20%20%20%20%20%20%20lShtCt%20%3D%20lShtCt%20%2B%201%0A%20%20%20%20%20%20%20%20%20%20%20%20ReDim%20Preserve%20vSheets(1%20To%20lShtCt)%0A%20%20%20%20%20%20%20%20%20%20%20%20vSheets(lShtCt)%20%3D%20ActiveSheet.Name%0A%20%20%20%20%20%20%20%20%20%20%20%20ActiveSheet.Copy%20ActiveSheet%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%0A%20%20%20%20Application.DisplayAlerts%20%3D%20False%0A%20%20%20%20ActiveSheet.Delete%0A%20%20%20%20Application.DisplayAlerts%20%3D%20True%0A%20%20%20%20Sheets(vSheets).Select%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20ActiveWindow.SelectedSheets.PrintOut%0A%20%20%20%20'New%20delete%20the%20temporary%20sheets%0A%20%20%20%20'%20Make%20a%20list%20of%20them%20by%20removing%20the%20first%20sheet%20from%20the%20list%20(since%20that%20is%20our%20original)%0A%20%20%20%20For%20lShtCt%20%3D%20LBound(vSheets)%20To%20UBound(vSheets)%20-%201%0A%20%20%20%20%20%20%20%20vSheets(lShtCt)%20%3D%20vSheets(lShtCt%20%2B%201)%0A%20%20%20%20Next%0A%20%20%20%20ReDim%20Preserve%20vSheets(1%20To%20lShtCt%20-%201)%0A%20%20%20%20'Now%20delete%0A%20%20%20%20Sheets(vSheets).Select%0A%20%20%20%20Application.DisplayAlerts%20%3D%20False%0A%20%20%20%20ActiveWindow.SelectedSheets.Delete%0A%20%20%20%20Application.DisplayAlerts%20%3D%20True%0AEnd%20Sub%0A%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-699636%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20to%20print%20double%20sided%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-699636%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20Jan%2C%20that's%20exactly%20it.%20Trying%20to%20figure%20out%20what%20the%20code%20means%20you%20added.%20Would%20you%20mind%20explaining%20it%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20going%20to%20try%20and%20break%20down%20all%20the%20code%20to%20get%20an%20understanding%20on%20whats%20being%20done%20line%20by%20line.%20Would%20you%20say%20its%20difficult%20to%20learn%20or%20once%20you%20get%20into%20it%20starts%20making%20more%20sense%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-699764%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20to%20print%20double%20sided%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-699764%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F275880%22%20target%3D%22_blank%22%3E%40az123330%3C%2FA%3E%20Here%20is%20a%20slightly%20adjusted%20version%20of%20the%20routine%20(less%20steps)%20including%20comments.%3C%2FP%3E%0A%3CPRE%3EOption%20Explicit%0A%0ASub%20PrintAllDates()%0A%20%20%20%20Dim%20vSheets()%20As%20Variant%20'Holds%20a%20list%20of%20the%20sheets%20to%20print%0A%20%20%20%20Dim%20printDate%20As%20Date%0A%20%20%20%20Dim%20startDate%20As%20Date%0A%20%20%20%20Dim%20endDate%20As%20Date%0A%20%20%20%20Dim%20lShtCt%20As%20Long%20'remembers%20how%20many%20sheets%20were%20added%0A%20%20%20%20'Tell%20VBA%20how%20many%20items%20to%20expect%2C%20it'll%20be%20at%20least%20one.%0A%20%20%20%20ReDim%20vSheets(1%20To%201)%0A%20%20%20%20Application.Dialogs(xlDialogPrinterSetup).Show%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20startDate%20%3D%20%2215%2F06%2F19%22%0A%20%20%20%20endDate%20%3D%20%2219%2F06%2F19%22%0A%20%20%20%20For%20printDate%20%3D%20startDate%20To%20endDate%0A%20%20%20%20%20%20%20%20If%20Weekday(printDate%2C%20vbMonday)%20%26lt%3B%206%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20ActiveSheet.Copy%20ActiveSheet%0A%20%20%20%20%20%20%20%20%20%20%20%20ActiveSheet.Range(%22C1%22)%20%3D%20printDate%0A%20%20%20%20%20%20%20%20%20%20%20%20lShtCt%20%3D%20lShtCt%20%2B%201%0A%20%20%20%20%20%20%20%20%20%20%20%20'Match%20the%20size%20of%20the%20vSHeets%20list%20to%20the%20number%20of%20sheet%20names%20added%0A%20%20%20%20%20%20%20%20%20%20%20%20ReDim%20Preserve%20vSheets(1%20To%20lShtCt)%0A%20%20%20%20%20%20%20%20%20%20%20%20'Store%20the%20new%20sheet%20name%0A%20%20%20%20%20%20%20%20%20%20%20%20vSheets(lShtCt)%20%3D%20ActiveSheet.Name%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%0A%20%20%20%20'Now%20select%20the%20newly%20inserted%20sheets%0A%20%20%20%20Sheets(vSheets).Select%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20'Print%20them%0A%20%20%20%20ActiveWindow.SelectedSheets.PrintOut%0A%20%20%20%20'Select%20them%20again%20to%20make%20sure%20they're%20still%20selected%20so%20we%20can%20delete%20them%0A%20%20%20%20Sheets(vSheets).Select%0A%20%20%20%20'SUppress%20the%20%22Are%20you%20sure%20you%20want%20to%20delete%22%20message%3A%0A%20%20%20%20Application.DisplayAlerts%20%3D%20False%0A%20%20%20%20'Now%20delete%20the%20temporary%20sheets%0A%20%20%20%20ActiveWindow.SelectedSheets.Delete%0A%20%20%20%20Application.DisplayAlerts%20%3D%20True%0AEnd%20Sub%0A%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-699907%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20to%20print%20double%20sided%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-699907%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThats%20very%20helpful%2C%20thanks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20only%20other%20issue%20there%20seems%20to%20be%20is%20the%20sheets%20look%20to%20print%20from%20the%20end%20date%20to%20the%20first%20date.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20only%20an%20issue%20because%20if%20the%20number%20of%20sheets%20is%20odd%20then%20its%20the%20first%20sheet%20which%20will%20print%20single%20rather%20than%20the%20end%20sheet.%20Only%20a%20minor%20thing%20but%20since%20its%20not%20mentioned%20in%20the%20code%20I%20am%20unsure%20why%20it%20behaves%20in%20this%20way%20rather%20than%20from%20start%20to%20finish%20like%20you'd%20expect.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-700092%22%20slang%3D%22en-US%22%3ERe%3A%20Macro%20to%20print%20double%20sided%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-700092%22%20slang%3D%22en-US%22%3E%3CP%3EOnly%20a%20very%20small%20change%20is%20needed%20to%20fix%20that.%20Find%20this%20line%20of%20code%3A%3CBR%20%2F%3E%3CBR%20%2F%3EActiveSheet.Copy%20ActiveSheet%3CBR%20%2F%3E%3CBR%20%2F%3Eand%20change%20it%20to%3A%3CBR%20%2F%3E%3CBR%20%2F%3EActiveSheet.Copy%20after%3A%3DActiveSheet%3C%2FP%3E%3C%2FLINGO-BODY%3E
az123330
Occasional Contributor

Hi,

 

I have created the attached spreadsheet and inserted the basic macro where it will print multiple sheets from and to the date range I specify in the macro. This is to act as a register and saves times copying and pasting the date each and every time.

 

The issue I am having is the sheets will not print duplex no matter what I do. I have tried changing the default printer and even put code in to select the printer before it prints the sheets. In setup duplex is selected but still comes out as single sheets.

 

Does anyone have an idea whats wrong?

 

The alternative is to change the macro so it does the same thing but instead prints all sheets into one PDF file. From there I can print however I do not know how to write this code?

 

Thanks in advance

7 Replies

@az123330 The problem is that your macro sends out a new printcommand for each date, which the printer then immediately processes. If the sheet would be larger so there are two pages to print, I bet those would be printed in duplex. Here is a macro that appears to do the trick. It creates temporary copies of the worksheet, enters the date into them and then prints all of them in one go and subsequently deletes the copies:

Sub PrintAllDates()
    Dim vSheets() As Variant
    Dim printDate As Date
    Dim startDate As Date
    Dim endDate As Date
    Dim lShtCt As Long
    ReDim vSheets(1 To 1)
    Application.Dialogs(xlDialogPrinterSetup).Show
    Application.ScreenUpdating = False
    startDate = "18/06/19"
    endDate = "19/06/19"
    For printDate = startDate To endDate
        ActiveSheet.Range("C1") = printDate
        lShtCt = lShtCt + 1
        ReDim Preserve vSheets(1 To lShtCt)
        vSheets(lShtCt) = ActiveSheet.Name
        ActiveSheet.Copy ActiveSheet
    Next
    Application.DisplayAlerts = False
    ActiveSheet.Delete
    Application.DisplayAlerts = True
    Sheets(vSheets).Select
    Application.ScreenUpdating = False
    ActiveWindow.SelectedSheets.PrintOut
    'New delete the temporary sheets
    ' Make a list of them by removing the first sheet from the list (since that is our original)
    For lShtCt = LBound(vSheets) To UBound(vSheets) - 1
        vSheets(lShtCt) = vSheets(lShtCt + 1)
    Next
    ReDim Preserve vSheets(1 To lShtCt - 1)
    'Now delete
    Sheets(vSheets).Select
    Application.DisplayAlerts = False
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
End Sub

 

@Jan Karel Pieterse 

 

Thats fantastic! I really need to learn how to code on this. Works exactly as intended.

 

A bit of an out the box question but do you know if I can somehow have it so it skips weekends throughout the year? The register is only meant for Mon-Fri and since its double sided I can't just get rid of the weekends because they end up printing on the same page as the weekdays.

 

Thanks again

@az123330 You can omit weekends like so:

Sub PrintAllDates()
    Dim vSheets() As Variant
    Dim printDate As Date
    Dim startDate As Date
    Dim endDate As Date
    Dim lShtCt As Long
    ReDim vSheets(1 To 1)
    Application.Dialogs(xlDialogPrinterSetup).Show
    Application.ScreenUpdating = False
    startDate = "15/06/19"
    endDate = "19/06/19"
    For printDate = startDate To endDate
        If Weekday(printDate, vbMonday) < 6 Then
            ActiveSheet.Range("C1") = printDate
            lShtCt = lShtCt + 1
            ReDim Preserve vSheets(1 To lShtCt)
            vSheets(lShtCt) = ActiveSheet.Name
            ActiveSheet.Copy ActiveSheet
        End If
    Next
    Application.DisplayAlerts = False
    ActiveSheet.Delete
    Application.DisplayAlerts = True
    Sheets(vSheets).Select
    Application.ScreenUpdating = False
    ActiveWindow.SelectedSheets.PrintOut
    'New delete the temporary sheets
    ' Make a list of them by removing the first sheet from the list (since that is our original)
    For lShtCt = LBound(vSheets) To UBound(vSheets) - 1
        vSheets(lShtCt) = vSheets(lShtCt + 1)
    Next
    ReDim Preserve vSheets(1 To lShtCt - 1)
    'Now delete
    Sheets(vSheets).Select
    Application.DisplayAlerts = False
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
End Sub

@Jan Karel Pieterse 

 

Thanks Jan, that's exactly it. Trying to figure out what the code means you added. Would you mind explaining it?

 

I am going to try and break down all the code to get an understanding on whats being done line by line. Would you say its difficult to learn or once you get into it starts making more sense?

@az123330 Here is a slightly adjusted version of the routine (less steps) including comments.

Option Explicit

Sub PrintAllDates()
    Dim vSheets() As Variant 'Holds a list of the sheets to print
    Dim printDate As Date
    Dim startDate As Date
    Dim endDate As Date
    Dim lShtCt As Long 'remembers how many sheets were added
    'Tell VBA how many items to expect, it'll be at least one.
    ReDim vSheets(1 To 1)
    Application.Dialogs(xlDialogPrinterSetup).Show
    Application.ScreenUpdating = False
    startDate = "15/06/19"
    endDate = "19/06/19"
    For printDate = startDate To endDate
        If Weekday(printDate, vbMonday) < 6 Then
            ActiveSheet.Copy ActiveSheet
            ActiveSheet.Range("C1") = printDate
            lShtCt = lShtCt + 1
            'Match the size of the vSHeets list to the number of sheet names added
            ReDim Preserve vSheets(1 To lShtCt)
            'Store the new sheet name
            vSheets(lShtCt) = ActiveSheet.Name
        End If
    Next
    'Now select the newly inserted sheets
    Sheets(vSheets).Select
    Application.ScreenUpdating = False
    'Print them
    ActiveWindow.SelectedSheets.PrintOut
    'Select them again to make sure they're still selected so we can delete them
    Sheets(vSheets).Select
    'SUppress the "Are you sure you want to delete" message:
    Application.DisplayAlerts = False
    'Now delete the temporary sheets
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
End Sub

@Jan Karel Pieterse

 

Thats very helpful, thanks.

 

The only other issue there seems to be is the sheets look to print from the end date to the first date.

 

This is only an issue because if the number of sheets is odd then its the first sheet which will print single rather than the end sheet. Only a minor thing but since its not mentioned in the code I am unsure why it behaves in this way rather than from start to finish like you'd expect.

Only a very small change is needed to fix that. Find this line of code:

ActiveSheet.Copy ActiveSheet

and change it to:

ActiveSheet.Copy after:=ActiveSheet

Related Conversations
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
PacketMon Components are not loading in WAC 1909
HotCakeX in Windows Admin Center on
2 Replies