I would like to either: 1) Close the print preview screen from a VB code module or 2) Print the worksheet from the print preview screen using VB. I have tried the suggestions given to be17 (thread 707-104728) without any success. I have also tried using the sendkeys command to send a "c" or {escape} to close the print preview window. I also tried using the sendkkeys command to send the letter "p" to print from the print preview screen.
The reason I want to do this is that the named range that I have for the print area changes based on the item selected. If I use the printout command I get the print area from the PREVIOUS item. However, if I open the worksheet in PrintPreview it shows the correct print range. Any help on this would be appreciated. The current code attached to a print "button" is:
Private Sub CommandButton1_Click()
CommandBars("worksheet menu bar").Enabled = True
CommandBars("standard").Enabled = True
Worksheets("Sheet2").Activate
Worksheets(2).ResetAllPageBreaks
Me.PageSetup.PrintArea _
= Me.Parent.Names(Me.Range("B3").Value).RefersToRange.Address
ActiveWindow.SelectedSheets.PrintOut
Application.SendKeys ("%fx")
Application.SendKeys ("n")
End Sub
Thanks!
John
The reason I want to do this is that the named range that I have for the print area changes based on the item selected. If I use the printout command I get the print area from the PREVIOUS item. However, if I open the worksheet in PrintPreview it shows the correct print range. Any help on this would be appreciated. The current code attached to a print "button" is:
Private Sub CommandButton1_Click()
CommandBars("worksheet menu bar").Enabled = True
CommandBars("standard").Enabled = True
Worksheets("Sheet2").Activate
Worksheets(2).ResetAllPageBreaks
Me.PageSetup.PrintArea _
= Me.Parent.Names(Me.Range("B3").Value).RefersToRange.Address
ActiveWindow.SelectedSheets.PrintOut
Application.SendKeys ("%fx")
Application.SendKeys ("n")
End Sub
Thanks!
John