Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default PrintPreview Zoom

Hi Group,

Using the code below to show the PrintPreview page
of a worksheet. Works fine, but is there a way to get
the PrintPreview page to open in the zoomed position?

Private Sub CommandButton3_Click()
UserForm1.Hide
ActiveSheet.PrintOut Preview:=True
UserForm1.Show
End Sub

Many thanks for some hints!

Brgds
CG Rosén


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default PrintPreview Zoom

I failed when I added a Sendkeys "{enter}" to your code:

Private Sub CommandButton3_Click()
UserForm1.Hide
Sendkeys "{enter}"
ActiveSheet.PrintOut Preview:=True
UserForm1.Show
End Sub

But even worse, when I was testing, I noticed that excel liked to help. If I
was zooming and closed print preview, the next time I did it, I was in zoom
mode.

If I wasn't zoomed, then the next time I did it, I wasn't in zoom mode.

I'm not sure if there's a way to find out what mode you're in (and then do
anything with it).



"CG Rosén" wrote:

Hi Group,

Using the code below to show the PrintPreview page
of a worksheet. Works fine, but is there a way to get
the PrintPreview page to open in the zoomed position?

Private Sub CommandButton3_Click()
UserForm1.Hide
ActiveSheet.PrintOut Preview:=True
UserForm1.Show
End Sub

Many thanks for some hints!

Brgds
CG Rosén


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default PrintPreview Zoom

Hi,

I think that there are little method to handle a preview window in excel
macro. I wrote some code using timer and sendkeys in Excel 2000. (this
may not be a good design)

Private Declare Function SetTimer Lib "user32" ( _
ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal hwnd As Long, ByVal uIDEvent As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hwndParent As Long, ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Private Declare Function GetWindow Lib "user32" ( _
ByVal hwnd As Long, ByVal uCmd As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function IsWindowEnabled Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" ( _
ByVal hwndLock As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const GW_CHILD = 5

Private g_zoom As Integer
Private g_keys_1 As String

Public Function TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal idEvent As Long, ByVal dwTime As Long) As Long
Dim xl As Long, prev As Long, i As Long
Dim scr1 As Long, scr2 As Long, scr3 As Long
On Error Resume Next
KillTimer 0, idEvent
For i = 1 To 10
xl = FindWindowEx(0, 0, "XLMAIN", Application.Caption)
prev = GetWindow(xl, GW_CHILD)
scr1 = FindWindowEx(prev, 0, "ScrollBar", vbNullString)
scr2 = FindWindowEx(prev, scr1, "ScrollBar", vbNullString)
scr3 = FindWindowEx(prev, scr2, "ScrollBar", vbNullString)
If scr1 < 0 And scr2 < 0 And scr3 < 0 Then
If IsWindowEnabled(scr3) = 0 Then
If IsWindowVisible(scr2) = g_zoom Then
SendKeys "z"
End If
If g_keys_1 < "" Then SendKeys g_keys_1
SetTimer 0, 0, 100, AddressOf TimerProc2
Exit Function
End If
End If
Sleep 100
Next
LockWindowUpdate 0
End Function

Public Function TimerProc2(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal idEvent As Long, ByVal dwTime As Long) As Long
On Error Resume Next
KillTimer 0, idEvent
LockWindowUpdate 0
End Function

Public Sub PreviewZoom(Zoom As Boolean, Optional SendKeysStr As String)
If Zoom Then g_zoom = 0 Else g_zoom = 1
g_keys_1 = SendKeysStr
LockWindowUpdate FindWindowEx(0, 0, "XLMAIN", Application.Caption)
SetTimer 0, 0, 0, AddressOf TimerProc
End Sub


Sub Test_PreviewZoom()
PreviewZoom False
ActiveSheet.PrintPreview
End Sub

Sub Test_PreviewZoom_2()
PreviewZoom True, "^{home}{down 6}{right 12}"
ActiveSheet.PrintPreview
End Sub

--
HTH,

okaizawa


Dave Peterson wrote:
I failed when I added a Sendkeys "{enter}" to your code:

Private Sub CommandButton3_Click()
UserForm1.Hide
Sendkeys "{enter}"
ActiveSheet.PrintOut Preview:=True
UserForm1.Show
End Sub

But even worse, when I was testing, I noticed that excel liked to help. If I
was zooming and closed print preview, the next time I did it, I was in zoom
mode.

If I wasn't zoomed, then the next time I did it, I wasn't in zoom mode.

I'm not sure if there's a way to find out what mode you're in (and then do
anything with it).



"CG Rosén" wrote:

Hi Group,

Using the code below to show the PrintPreview page
of a worksheet. Works fine, but is there a way to get
the PrintPreview page to open in the zoomed position?

Private Sub CommandButton3_Click()
UserForm1.Hide
ActiveSheet.PrintOut Preview:=True
UserForm1.Show
End Sub

Many thanks for some hints!

Brgds
CG Rosén



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default PrintPreview Zoom

I'm not sure I'd depend on sendkeys, but your code worked ok for me in my simple
tests in xl2003, too.



okaizawa wrote:

Hi,

I think that there are little method to handle a preview window in excel
macro. I wrote some code using timer and sendkeys in Excel 2000. (this
may not be a good design)

Private Declare Function SetTimer Lib "user32" ( _
ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal hwnd As Long, ByVal uIDEvent As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hwndParent As Long, ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Private Declare Function GetWindow Lib "user32" ( _
ByVal hwnd As Long, ByVal uCmd As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function IsWindowEnabled Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" ( _
ByVal hwndLock As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const GW_CHILD = 5

Private g_zoom As Integer
Private g_keys_1 As String

Public Function TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal idEvent As Long, ByVal dwTime As Long) As Long
Dim xl As Long, prev As Long, i As Long
Dim scr1 As Long, scr2 As Long, scr3 As Long
On Error Resume Next
KillTimer 0, idEvent
For i = 1 To 10
xl = FindWindowEx(0, 0, "XLMAIN", Application.Caption)
prev = GetWindow(xl, GW_CHILD)
scr1 = FindWindowEx(prev, 0, "ScrollBar", vbNullString)
scr2 = FindWindowEx(prev, scr1, "ScrollBar", vbNullString)
scr3 = FindWindowEx(prev, scr2, "ScrollBar", vbNullString)
If scr1 < 0 And scr2 < 0 And scr3 < 0 Then
If IsWindowEnabled(scr3) = 0 Then
If IsWindowVisible(scr2) = g_zoom Then
SendKeys "z"
End If
If g_keys_1 < "" Then SendKeys g_keys_1
SetTimer 0, 0, 100, AddressOf TimerProc2
Exit Function
End If
End If
Sleep 100
Next
LockWindowUpdate 0
End Function

Public Function TimerProc2(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal idEvent As Long, ByVal dwTime As Long) As Long
On Error Resume Next
KillTimer 0, idEvent
LockWindowUpdate 0
End Function

Public Sub PreviewZoom(Zoom As Boolean, Optional SendKeysStr As String)
If Zoom Then g_zoom = 0 Else g_zoom = 1
g_keys_1 = SendKeysStr
LockWindowUpdate FindWindowEx(0, 0, "XLMAIN", Application.Caption)
SetTimer 0, 0, 0, AddressOf TimerProc
End Sub

Sub Test_PreviewZoom()
PreviewZoom False
ActiveSheet.PrintPreview
End Sub

Sub Test_PreviewZoom_2()
PreviewZoom True, "^{home}{down 6}{right 12}"
ActiveSheet.PrintPreview
End Sub

--
HTH,

okaizawa

Dave Peterson wrote:
I failed when I added a Sendkeys "{enter}" to your code:

Private Sub CommandButton3_Click()
UserForm1.Hide
Sendkeys "{enter}"
ActiveSheet.PrintOut Preview:=True
UserForm1.Show
End Sub

But even worse, when I was testing, I noticed that excel liked to help. If I
was zooming and closed print preview, the next time I did it, I was in zoom
mode.

If I wasn't zoomed, then the next time I did it, I wasn't in zoom mode.

I'm not sure if there's a way to find out what mode you're in (and then do
anything with it).



"CG Rosén" wrote:

Hi Group,

Using the code below to show the PrintPreview page
of a worksheet. Works fine, but is there a way to get
the PrintPreview page to open in the zoomed position?

Private Sub CommandButton3_Click()
UserForm1.Hide
ActiveSheet.PrintOut Preview:=True
UserForm1.Show
End Sub

Many thanks for some hints!

Brgds
CG Rosén




--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help! Print Preview Zoom is Grayed Out...Doesn't zoom. PK Excel Discussion (Misc queries) 0 July 20th 09 03:33 PM
PrintPreview Gerry Verschuuren Excel Discussion (Misc queries) 5 October 23rd 07 06:24 PM
PrintPreview doesn't work Roy Barr Excel Programming 2 March 28th 05 01:22 PM
PrintPreview Question JimP Excel Programming 2 November 12th 04 02:47 PM
printpreview freezing GregJG[_10_] Excel Programming 0 July 4th 04 12:01 AM


All times are GMT +1. The time now is 04:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"