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
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}"
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.