Solved

Excel Zoom Property

Posted on 2002-07-02
8
752 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

816 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