Solved

Excel Zoom Property

Posted on 2002-07-02
8
755 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing a value with stream reader AFTER a ";" 3 92
Visual Studio 2005 text editor 10 57
Set email body to html using vbscript 6 98
Zip Folders Using Chilkat Routines 1 87
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 …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

710 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