VBA Printing Error

I'm having trouble with my VBA print command - I have a module that helps me with page formatting/setup >  print worksheet. However I'm having some problems with the second half - where the first time I run this module, it doesn't apply the page formatting. I will cancel the print job, then run the module for the second time and only then will the page formatting be correct.

This part is the page setup: (rather new to VBA so please excuse if there are unnecessary lines in here!)
Sub printlist()
Dim LR As Long

With ActiveWorkbook.Sheets("Masterlist Print Format")
     LR = .Range("B" & Rows.count).End(xlUp).Row
  
    
     Application.PrintCommunication = False
    With Sheets("Masterlist Print Format").PageSetup
        .PrintArea = "A1:S" & LR
        .Orientation = xlLandscape
        
        .FitToPagesWide = 1
        .FitToPagesTall = False
        .PrintTitleRows = "$2:$3"
        .PrintTitleColumns = ""
        .CenterFooter = "Collated Chemical Listings" & Chr(10) & "Page &P of &N"
        .PrintQuality = 600
        .CenterHorizontally = True
        .CenterVertically = False
        .Draft = False
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .RightMargin = Application.InchesToPoints(0.3)
        .TopMargin = Application.InchesToPoints(0.25)
        .BottomMargin = Application.InchesToPoints(0.4)
        .HeaderMargin = Application.InchesToPoints(0.2)
        .FooterMargin = Application.InchesToPoints(0.2)
    End With

Open in new window


and the second part:
    .PrintPreview
       Application.Dialogs(xlDialogPrinterSetup).Show
  If Not (Application.Dialogs(xlDialogPrinterSetup).Show) Then Exit Sub
  ' .PrintOut From:=1, To:=2
 
End With
End Sub

Open in new window


When running the module for the first time, this is what shows on the print preview. I've also tried printing it out directly without the print preview line but the same thing is printed out. Mainly it does not set to landscape and does not fit page to 1 page wide


Subsequent attempts will give me the correct format. When i close the program and run it for the first time, it brings me back to the incorrect format.
Correct format

I've tried to google but it doesn't seem like a common problem. Hope you can help!
Pearlyn TanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try
Application.PrintCommunication = True
DoEvents

Open in new window

before PrintPreview

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pearlyn TanAuthor Commented:
Thank you!! This works!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Printers and Scanners

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.