ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   PrintPreview (https://www.excelbanter.com/excel-discussion-misc-queries/163137-printpreview.html)

Gerry Verschuuren

PrintPreview
 
How can a PrintPreview screen be close through VBA code?

Thank you in advance for your help.

Bob I

PrintPreview
 
maybe Sendkey the Escape key?

Gerry Verschuuren wrote:

How can a PrintPreview screen be close through VBA code?

Thank you in advance for your help.



Gerry Verschuuren

PrintPreview
 
No that doesn't do the job

"Bob I" wrote:

maybe Sendkey the Escape key?

Gerry Verschuuren wrote:

How can a PrintPreview screen be close through VBA code?

Thank you in advance for your help.




Bob I

PrintPreview
 
What about Alt+C ?

Gerry Verschuuren wrote:
No that doesn't do the job

"Bob I" wrote:


maybe Sendkey the Escape key?

Gerry Verschuuren wrote:


How can a PrintPreview screen be close through VBA code?

Thank you in advance for your help.





Gerry Verschuuren

PrintPreview
 
The problem seems to be that I use a MsgBox which shows up on the original
sheet and not on the Preview window. This is the code I am trying to run:

Sub Test()
Dim oWS As Worksheet
For Each oWS In Worksheets
oWS.PrintPreview
If MsgBox("Close?", vbYesNo) = vbYes Then SendKeys "{ESC}"
Next oWS
End Sub

"Bob I" wrote:

What about Alt+C ?

Gerry Verschuuren wrote:
No that doesn't do the job

"Bob I" wrote:


maybe Sendkey the Escape key?

Gerry Verschuuren wrote:


How can a PrintPreview screen be close through VBA code?

Thank you in advance for your help.





Bob I

PrintPreview
 
As I recall those message/dialog boxes have the focus. Until you clear
that, you can't access the window, because it doesn't have focus. In
looking at your code, I think you could dispense with
"If MsgBox("Close?", vbYesNo) = vbYes Then " and just use

SendKeys "{ESC}"


Gerry Verschuuren wrote:

The problem seems to be that I use a MsgBox which shows up on the original
sheet and not on the Preview window. This is the code I am trying to run:

Sub Test()
Dim oWS As Worksheet
For Each oWS In Worksheets
oWS.PrintPreview
If MsgBox("Close?", vbYesNo) = vbYes Then SendKeys "{ESC}"
Next oWS
End Sub

"Bob I" wrote:


What about Alt+C ?

Gerry Verschuuren wrote:

No that doesn't do the job

"Bob I" wrote:



maybe Sendkey the Escape key?

Gerry Verschuuren wrote:



How can a PrintPreview screen be close through VBA code?

Thank you in advance for your help.






All times are GMT +1. The time now is 10:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com