473,811 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open Excel at 90% zoom

13 New Member
Hello
I was able to create/open an Excel ss from vb.net but how do I open it at 90% something like...
ActiveWindow.Zo om = 90

but I get "Activewind ow is not declared." I'm really new at this, please help
Sep 6 '10 #1
11 15735
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Although the Activewindow property can be referred to on its own from within Excel, where the Application object is implied, you can't do this outside of Excel. You must fully-qualify the Excel application server object instead.

Using VBA as an illustration

Expand|Select|Wrap|Line Numbers
  1. Dim objExcel as Excel.Application
  2. Set objExcel as New Excel.Application
  3. .
  4. .
  5. objExcel.Activewindow.Zoom = 90
-Stewart
Sep 7 '10 #2
Stevecb
13 New Member
Hello - thanks for the reply. I tried your suggestion and
I'm getting "Object reference not set to an instance of an object."

I have this within a procedure that creates the ss
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Button1_Click(ByVal sender As System.Object, _
  2.         ByVal e As System.EventArgs) Handles Button1.Click
  3.  
  4.         Dim objRange As Excel.Range = Nothing
  5.         xlApp = New Excel.ApplicationClass
  6.         xlWorkBook = xlApp.Workbooks.Add(misValue)
  7.         xlWorkSheet = xlWorkBook.Sheets("Sheet1")
  8.         objExcel = New Excel.Application
  9.         objExcel.ActiveWindow.Zoom = 90
  10.  
I thought it would reference the open Excel window, or so I thought
Sep 7 '10 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
I was using objExcel as an example of an object variable name. You have in effect declared a second Excel application object, which has no connection at all to the object called xlApp you have already instantiated. Even worse, until you open a workbook in the objExcel instance there is no active window to refer to.

Now that I know what objects you have declared there are several choices, as the Application object is available from a Worksheet object as well as directly. Perhaps simplest in your case is to replace lines 8 and 9 above with

Expand|Select|Wrap|Line Numbers
  1. xlWorkSheet.Application.ActiveWindow.Zoom = 90
-Stewart
Sep 7 '10 #4
Stevecb
13 New Member
I changed it to this and it doesn't error but it doesn't work either...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, _
  2.         ByVal e As System.EventArgs) Handles Button1.Click
  3.  
  4.         Dim objRange As Excel.Range = Nothing
  5.         xlApp = New Excel.ApplicationClass
  6.         xlWorkBook = xlApp.Workbooks.Add(misValue)
  7.         xlWorkSheet = xlWorkBook.Sheets("Sheet1")
  8.         objExcel = New Excel.Application
  9.         'objExcel.ActiveWindow.Zoom = 90
  10.         xlApp.ActiveWindow.Zoom = 90
  11.  
Sep 7 '10 #5
Stevecb
13 New Member
Sorry, getting cross threaded. It works on sheet1 could I bother you to explain how to get it applied to all sheets not just the first. I tried...

xlWorkSheet.App lication.Active Workbook.zoom = 90

but it didn't like it.
Sep 7 '10 #6
Stewart Ross
2,545 Recognized Expert Moderator Specialist
I've adapted what you provided to my VBA environment. I notice that the editor is not happy with variable names xlWorksheet, for example, as these appear to clash with system constants. I have renamed all such instances below.

I have tested the code below running from MS Access in VBA, with the application set Visible to cross check, and it does indeed zoom the active worksheet window (sheet 1) to 90%.

Expand|Select|Wrap|Line Numbers
  1. Public Sub Test()
  2.     Dim xlApp As New Excel.Application
  3.     Dim objxlWorkbook As Excel.Workbook
  4.     Dim objxlWorksheet As Excel.Worksheet
  5.     xlApp.Visible = True
  6.     Set objxlWorkbook = xlApp.Workbooks.Add()
  7.     Set objxlWorksheet = objxlWorkbook.Sheets("Sheet1")
  8.     objxlWorksheet.Application.ActiveWindow.Zoom = 90
  9. End Sub
I removed the name of the variable misValue from the Workbooks.Add method - I cannot see where it is declared or passed to the sub, and without knowing what its value is I do not know what template it is referring to. For test purposes I'm simply adding a new workbook.

-Stewart
Sep 7 '10 #7
Stevecb
13 New Member
Thanks for your patience it has been very helpful. I was hoping to open all the sheets at 90% and tried to loop through with this...

With xlWorkBook
For intCount = 1 To 7
xlApp.ActiveWin dow.Zoom = 90 ' open sheet at 90%
Next
End With

but I think it just loops through numbers 1 - 7 and doesn't zoom each sheet
Sep 8 '10 #8
Stewart Ross
2,545 Recognized Expert Moderator Specialist
You need to loop through the worksheets collection of the application object and activate each sheet before it can be zoomed. Using your counter approach, this would be done like this:

Expand|Select|Wrap|Line Numbers
  1. With xlApp
  2.     For intCount = 1 To .Worksheets.Count
  3.         .Worksheets(intCount).Activate
  4.         .ActiveWindow.Zoom = 90
  5.     Next
  6. End With
  7.  
Note the change to the application object from the workbook for the With, as the Workbook object was not being referred to in the With you showed.

There is a similar approach which does not use a counter as such, but a worksheet object within a FOR..EACH loop:

Expand|Select|Wrap|Line Numbers
  1. Dim objExcelWS As Excel.Worksheet
  2. With xlApp
  3.     For Each objExcelWS In .Worksheets
  4.         objExcelWS.Activate
  5.         .ActiveWindow.Zoom = 90
  6.     Next
  7. End With
These are general approaches which zoom all the worksheets in a workbook, regardless of how many or how few are in the current workbook. Using a constant such as 7 as the limit of the sheet count invites errors when opening workbooks that do not have 7 worksheets.

-Stewart
Sep 8 '10 #9
Stevecb
13 New Member
Thank you very much Stewart for your patience and expertise. It was a huge help!
Sep 8 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9844
by: JM | last post by:
Hi I have been trying to open Excel 2003 but I am having rotten luck. Just can't see to get it working. I looked at this article... http://www.codeproject.com/csharp/csharp_excel.asp?print=true Anyone have any ideas?
1
1907
by: Micke | last post by:
I want to open Excel from an aspx page, put some records in there, format them and close the excel file. I can't open the Excel application. It says Cannot create ActiveX component. Here is the code: Imports Excel = Microsoft.Office.Interop.Excel Public Class MG Inherits System.Web.UI.Page
6
10828
by: Micke | last post by:
Hi, I'm trying to open an Excel file from an aspx with following code: Imports Excel = Microsoft.Office.Interop.Excel Dim oExcel As New Excel.Application Dim oBooks As Excel.Workbooks oBooks.Open("C:\XML\PriceList.xls") All I get is:
3
7429
by: Jennyfer Barco | last post by:
Hello, I have a question, how can I open Microsoft Excel from .NET. I only need to open a new file in Excel and paste some information and set the Microsoft Excel as the enabled aplication, so the user can continue working in Excel and he'll save the information I pasted. I tried this but doesn't open Excel at all, but it does save the file c:\test.xls with the value "This is column B row 2" in colum B and row 2: Dim xlApp As...
1
3709
by: Bon | last post by:
Hello all I create a form with three buttons in MS Access 2000. They are Open Excel Template, Save Draft and Save Final. When I click the Open Excel Template button, the Excel template will be opened. Inside the Excel template, I have assigned a draft watermark to the Print icon. When the Print icon is clicked, the draft watermark and print dialog box is shown. After the user print/edit data in the Excel template, s/he has to click
2
5966
by: k-w | last post by:
Hi all In vb I do: Dim Ex As New Excel.Application Ex.Workbooks.Open "c:\tmp\Book1.xls" Similar code in VC doesn't work:
9
3463
by: Looch | last post by:
Was hoping I could get some insight on this. I added a text box and command button to a web page and added the code in the .vb file to open an existing Excel file based on what was typed in the text box. I'm getting the I'm new to ASP so... Can I have the Excel file anywhere or does it have to be in an IIS/ASP related folder? (Getting the ASP user not authorized 80070005 error)
1
1671
by: trandtun | last post by:
Hello, I use VS2005,Excel2003,WinXP-sp2 and create asp.net web application project to open the excel file. I want to show excel application. If I use visual development server type from project propertes,I get it. But if I use IIS Web server type ,I can't get.
3
6676
by: Mel | last post by:
How do I open an Excel file as a read only document? It would be okay if it opened in the browser window but I don't want the user to save any changes and stomp over my original file on the network. Can I somehow save it to the client machine and then open it? What is the best method? (using Asp.net 2.0, vb.net)
4
14595
by: mld01s | last post by:
Hi all!! I need help, I have been stuck for a few days on this one. I am trying to open an excel table from a command button in Access. The excel table has an auto_open macro, that is supposed to run everytime I open excel. When I navigate to the excel file, and open it, it autoruns the macro with no problems. When I go from Access hit the command, the excel table opens with no problem, but the macro does not auto run on start. Here is...
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.