473,411 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Calling F9 function in Excel

21
Hi,

Does anyoe know how to call the F9 key function (Calculate Sheet) using C#?

Thanks.
May 25 '07 #1
3 2821
SammyB
807 Expert 512MB
Hi,

Does anyoe know how to call the F9 key function (Calculate Sheet) using C#?

Thanks.
xlSheet.Calculate();
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using Excel = Microsoft.Office.Interop.Excel; // Add a reference to Microsoft.Office.Interop.Excel.dll
  9. namespace ExcelInterop
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private void button1_Click(object sender, EventArgs e)
  18.         {
  19.             // Object for missing (or optional) arguments.
  20.             object oMissing = System.Reflection.Missing.Value;
  21.             // Create an instance of Microsoft Excel, make it visible,
  22.             // and open Book1.xls.
  23.             Excel.ApplicationClass xlApp = new Excel.ApplicationClass();
  24.             xlApp.Visible = true;
  25.             Excel.Workbooks xlBooks = xlApp.Workbooks;
  26.             Excel._Workbook xlBook = null;
  27.             xlBook = xlBooks.Open("c:\\book1.xls", oMissing, oMissing,
  28.                 oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
  29.                 oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
  30.             // Calculate
  31.             Excel.Sheets xlSheets = xlBook.Worksheets;
  32.             Excel._Worksheet xlSheet = xlSheets[1] as Excel._Worksheet;   //Could be a Chart
  33.             xlApp.Calculate();    //or
  34.             if (xlSheet != null) xlSheet.Calculate();            
  35.             // Quit Excel and clean up.
  36.             System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);
  37.             xlSheets = null;
  38.             System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
  39.             xlSheet = null;
  40.             xlBook.Close(true, oMissing, oMissing);
  41.             System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
  42.             xlBook = null;
  43.             System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);
  44.             xlBooks = null;
  45.             xlApp.Quit();
  46.             System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
  47.             xlApp = null;
  48.         }
  49.     }
  50. }
  51.  
May 25 '07 #2
you can use things like System.Windows.Forms.SendKeys

Win32 Library's SendInput and SetForeGroundWindow type calls using "Using Win32 and Other Libraries" from the .Net documentation.
May 25 '07 #3
SammyB
807 Expert 512MB
you can use things like System.Windows.Forms.SendKeys

Win32 Library's SendInput and SetForeGroundWindow type calls using "Using Win32 and Other Libraries" from the .Net documentation.
Oo hey, good call. It does sound like that is what Nitesh wanted to do. So, tell us, Nitesh, what are you trying to do? Here is more on SendKeys from Microsoft, http://msdn2.microsoft.com/en-us/lib...48(vs.80).aspx
May 25 '07 #4

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

Similar topics

4
by: Bob Murdoch | last post by:
I have an ASP application that calls a COM function to create a custom report as an Excel file. This works in a synchronous fashion, as long as the report does not take too long to create. If...
3
by: Gal merom | last post by:
I would like to run a function of one access file from another access/excel file, How can i do that? For example: I want to write a procedure in Excel VB that will call another function in an...
8
by: Rob Kellow | last post by:
Hello, I'm working on an application for use within my company on our intranet that will be used to gather some information and store some of the info in a SQL Server database and the rest of the...
2
by: cr113 | last post by:
I just upgraded from Office 2000 to Office 2003. My VB.NET Excel macro calls don't work any longer. Here is how I make my Excel macro call from VB.NET: Dim objExcel as Excel.Application ...
1
by: jobxyz | last post by:
Hi I am trying to call the excel function linest from VB using automation. the call Slope1 = Excel.WorksheetFunction.Index(Excel.WorksheetFunction.LinEst(y, x),1) works fine as long as x...
0
by: Gunther | last post by:
Hi, I have tried the example from the KB article 817248 (http://support.microsoft.com/kb/817248/en-us) in Visual Basic AND in C# with ..NET Framework 2.0: <ComClass(ComClass1.ClassId,...
6
by: RB Smissaert | last post by:
Made a C++ dll with MS VC6 and trying to call the dll from Excel VBA. This is the code in the .cpp file: #include "stdafx.h" #include <string> #include <math.h> using namespace std;
1
by: Jaime Leivers | last post by:
Here's a median function in access that you can call in any query. You could change this to any excel function you wanted. Most people can find the windows help file that says how to call an excel...
3
by: keirnus | last post by:
Hello once again... I made a function in Excel. The function does some error checking within the Excel file. To be easy for me, I want my code in MS Access to simply call the function in Excel....
0
by: djanarda | last post by:
Hi, I am newbie to c# coding. I am trying to call the MS-Excel Correl() in my C# code. From a decently comprehensive search on google I found that there is a Excel Interop COM library which could...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
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...

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.