Solved

Excel Zoom Property

Posted on 2002-07-02
8
753 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
ID: 7125516
Hi emoreau,

you can try

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

HAGD:O)Bruintje
0
 
LVL 70

Author Comment

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

Expert Comment

by:bruintje
ID: 7125865
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 6

Expert Comment

by:pierrecampe
ID: 7128284
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
 
LVL 70

Author Comment

by:Éric Moreau
ID: 7129776
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
ID: 7130337
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 70

Author Comment

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

Expert Comment

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 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