Solved

Excel Zoom Property

Posted on 2002-07-02
8
745 Views
Last Modified: 2008-03-17
I use Excel 2000 via automation from a VB application.

After setting FitToPagesWide (to 1) and FitToPagesTall (to False), I need to retreive the numerical value of the Zoom property (just like we can see it into the page preview setup in Excel).
0
Comment
Question by:Éric Moreau
  • 3
  • 3
  • 2
8 Comments
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi emoreau,

you can try

'writing
Worksheets("Sheet1").PageSetup.Zoom = 150
'reading
MsgBox Worksheets("Sheet1").PageSetup.Zoom

HAGD:O)Bruintje
0
 
LVL 69

Author Comment

by:Éric Moreau
Comment Utility
No. I need to set the FitToPagesWide property and retreive the Zoom value.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
that's funny, seems to be not available through the print preview but only through page setup tho both come up with the same dialogs

maybe someone else has an idea
0
 
LVL 6

Expert Comment

by:pierrecampe
Comment Utility
dont know if this is of any help,it probably is a terrible kludge,but maybe it will bring you to some ideas
i made the following macro in word:
Sub Doit()
    Dim a
    Dim b
    Dim c
    With Application.ActiveSheet.PageSetup
        a = .FitToPagesWide
        b = .FitToPagesTall
        .FitToPagesWide = False
        .FitToPagesTall = False
    End With
    With Application.Dialogs(xlDialogPageSetup)
        .Show
        .Show
    End With
    c = Application.ActiveSheet.PageSetup.Zoom
    With Application.ActiveSheet.PageSetup
        .FitToPagesWide = a
        .FitToPagesTall = b
        .Zoom = False
    End With
    MsgBox c
End Sub

this will let you know the zoom without changing anything
problem is that it still requeres user intervention to press the ok button,because the dialog seems to be a modal window
but maybe if before the .show you start another program
that continualy searches for the pagesetup window and when it finds it sends an enter to it, it may work


0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 69

Author Comment

by:Éric Moreau
Comment Utility
As soon as the settings are set to FitToPage, the Zoom property is containing False (instead of the numerical value).
0
 
LVL 6

Accepted Solution

by:
pierrecampe earned 200 total points
Comment Utility
ok so here a vb program ( or 2) that does what you asked
i know it is a kludge, and may not suit your needs, but it does what you asked
program1:
Dim objExcel As Excel.Application
Private Sub Command1_Click()
    Dim a
    Dim b
    Dim c
    Set objExcel = New Excel.Application
    objExcel.Visible = True
    objExcel.Workbooks.Add
    For i = 65 To 85
        ab$ = Chr(i) & i - 64
        objExcel.Range(ab$).Select
        objExcel.ActiveCell.FormulaR1C1 = Chr(i)
    Next
    With objExcel.ActiveSheet.PageSetup
       .Zoom = False
       .FitToPagesWide = 1
       .FitToPagesTall = 1
       a = .FitToPagesWide
       b = .FitToPagesTall
    End With
   
    Shell "C:\0Test\1\Projtimer.exe 4"

    With objExcel.Dialogs(xlDialogPageSetup)
         .Show
         .Show
         With objExcel.ActiveSheet.PageSetup
             .FitToPagesWide = False
             .FitToPagesTall = False
         End With
         .Show
         .Show
    End With
    With objExcel.ActiveSheet.PageSetup
       c = .Zoom
       .FitToPagesWide = a
       .FitToPagesTall = b
       .Zoom = False
   End With
    MsgBox "The Zoom At This Moment Is " & c & " And The FitToPagesWide Is " & a
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set objExcel = Nothing
End Sub

program2:( this program is named 'Projtimer.exe')

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim Cmmnd As Integer
Dim Number As Integer

Private Sub Form_Load()
    Me.Visible = False
    Timer1.Interval = 1000
    Cmmnd = Command
End Sub

Private Sub Timer1_Timer()
    'Beep
    Dim WinWnd As Long
    WinWnd = FindWindow(vbNullString, "Page Setup")
    If WinWnd Then
       SendKeys "{ENTER}", True
       Number = Number + 1
    End If
    If Number = Cmmnd Then
       Unload Me
    End If
End Sub
0
 
LVL 69

Author Comment

by:Éric Moreau
Comment Utility
It is not "elegant" but it is doing the job.
0
 
LVL 6

Expert Comment

by:pierrecampe
Comment Utility
i know it's a kludge
but thanks for the points
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now