473,800 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Taking control of an existing instance of Excel

User has opened an excel file and I want to take the control of the file. In
VB6 was not hard. Just I needed to use "GetObject" then I could select the
workbook. But now I don't know how to do it in C#.

Thanks
Nov 17 '05 #1
2 1891
Adine,

You will want to use the static GetActiveObject method on the Marshal
class to do this.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Adine" <ad********@yah oo.com> wrote in message
news:s5******** *************** *******@magma.c a...
User has opened an excel file and I want to take the control of the file.
In VB6 was not hard. Just I needed to use "GetObject" then I could select
the workbook. But now I don't know how to do it in C#.

Thanks

Nov 17 '05 #2
I used:

excelObj =
(Excel.Applicat ion)System.Runt ime.InteropServ ices.Marshal.Ge tActiveObject(" Excel.Applicati on");

but did not work. I have opened 2 excel files but excelObj.Workbo oks.Count
shows zero!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:O8******** ******@TK2MSFTN GP14.phx.gbl...
Adine,

You will want to use the static GetActiveObject method on the Marshal
class to do this.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Adine" <ad********@yah oo.com> wrote in message
news:s5******** *************** *******@magma.c a...
User has opened an excel file and I want to take the control of the file.
In VB6 was not hard. Just I needed to use "GetObject" then I could select
the workbook. But now I don't know how to do it in C#.

Thanks


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6802
by: S.W. Rasmussen | last post by:
With the risk of being accused of multi-posting I would like to draw the attention to a serious visual basic/windows issue discussed in the microsoft.public.vb.bugs newsgroup. As pointed out below by Norman Diamond the bug may result in loss of data when saving files with the standard common dialog control. Norman Diamond describes the problem as follows: ---------- In VB6 SP6, VB6 SP5, and possibly others, the common dialog box...
0
1070
by: jellimy | last post by:
I'm using the WebBrowser control in a Windows form to display an Excel spreadsheet. Most of the time this seems to work quite well. However, when I have opened Excel independantly of my application, I can not control that instance of Excel any more, I mean, I can not interact with the instance of Excel, or use any of Macro of Excel itself. Does anyone know a way of dealing with that problem? Actually, I saw the solution of Visual C++ in...
8
3373
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to process this .txt file. Goal: I am working on a vba script to:
1
8380
by: Fred Morrison | last post by:
In VB6, I would check to see if Excel was already running by this technique Private m_booExcelCreatedHere As Boolean Dim xlApp as Excel.Application On Error Resume Next ' temporarily suppress error handler Set xlApp = GetObject(,"Excel.Application") On Error GoTo PROC_ERR ' resume normal error handling If xlApp Is Nothing Then
2
4926
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is being updated by some other process through remoting. When the page loads, I init the tree, and in my browser I can see the initialized tree. The problem is that every time that I receive update to tree from the remote process,
2
2187
by: leeedw | last post by:
Hi everyone, I use the following code whenever I export to Excel from VB.NET objExcel = New Excel.Application() objWorkBooks = objExcel.Workbooks objWorkBook = objWorkBooks.Add objWorkSheet = objExcel.ActiveWorkbook.ActiveSheet The problem is that every time I need to export, it results in creating
3
3033
by: Ian Dunn | last post by:
I'm simply trying to access an instance of Excel that has been opened manually by the user in order to put a few values in the existing sheet. Here's the code I've tried: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet oXL = GetObject(, "Excel.Application") oWB = oXL.ActiveWorkbook oSheet = oWB.ActiveSheet
1
1378
by: shapper | last post by:
Hello, I am creating a user control where an Asp.Net control is used. It can be either a button, an image button or a label. I am trying to "expose" the Asp.Net control properties and events in the page where the user control is used. For that I defined a property as follows:
5
3753
by: John Kotuby | last post by:
Hi all, This is my first time trying to creaet and use a custome Web Control in a Web Site project in ASP.NET 2.0 with VS 2005 and VB. I created the control in a separate Web Control Library project. The original code for that control was written in VS 2003 for .NET 1.1. I created a Web Project and pulled the VB module into the project. I compared the syntax to the VB template classs that was built and it looked very similar. I then...
0
9691
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
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6813
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
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.