How to control running Excel instance
How to control running Excel instance
How to control running Excel instance
How to control running Excel instance
How to control running Excel instance
How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance
How to control running Excel instance How to control running Excel instance
How to control running Excel instance
Go Back  Xtreme Visual Basic Talk > > > How to control running Excel instance


Reply
 
Thread Tools Display Modes
  #1  
Old 08-19-2011, 07:38 AM
xploit xploit is offline
Newcomer
 
Join Date: Aug 2011
Posts: 2
Default How to control running Excel instance


Hello,

I try to develop a automation-add-in for Excel which can get some data from our SQL DB.
So i call my add from an Excel-cell.. like "=getThisFromDb()"...
This works totally fine! But what if i want to write to another cell then just give a return value?
I managed to get the running instance of excel. I can read from it. I can open a new document in it and write to it.
->> But can't write to the Worksheet that called me!!

I already tried many diffrent ways to do this...
I would really appreciate if anybody could help me!

Have a nice WE!
Reply With Quote
  #2  
Old 08-22-2011, 01:49 AM
xploit xploit is offline
Newcomer
 
Join Date: Aug 2011
Posts: 2
Default 10$ // 7€ for the help the leads me to my aim^^

I try again to explain my problem...

There are two approches:

1.) (what i've already did):

"=getSomeData" (in an Excel-cell) calls my VB - function throgh a COM-Server. The function returns a value which will be written to the calling cell with the "=getSomeData" init.



2.) (what i want to do or where my problem is):

When my function is called (the same way with "=getWhatever()") i want to write to the Excel worksheet instead of just "return whatever"...

So i wrote a code something like...

xlApp = CType(GetObject(, "Excel.Application"), Excel.Application)
xlBook = xlApp.ActiveWorkbook
xlSheet = CType(xlBook.ActiveSheet, Excel.Worksheet)
Dim rnRange As Excel.Range = xlSheet.Range("A4")
rnRange.Value = "test"

And whis returns me an "unknow ~HRESULT Error"... The point is, that this approach works when i exchange the line "xlBook = ...." with this line:

xlBook = xlApp.Workbooks.Open("C:\whatever\myExcelFile.xlsx")

So when i open a new worksheet / workbook i can write to any cell.. but when i want to write to the worksheet that called my function, the code fails...



Is there a readyonly protection? Are there multiple approaches to "get the running process" with different possibilities afterwards (read/write...)?

Could it be, that another programm already "took" the process so i cant write to it? (the COM Server?.. If so, there must be a option to write to Excel through this COMServer!?)



I'm also open for another way.. I just need to:

- Call a piece of VB.NET code from excel

- write to the worksheet that called the code



Your help will be greatly appreciated!! (Even if you just want to tell me that i should move this to another section... should I?)
Reply With Quote
  #3  
Old 08-28-2011, 01:44 PM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Welcome to t he forum

I believe the following KB-article from Microsoft will get You started:

Excel COM add-ins and Automation add-ins
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
How to control running Excel instance
How to control running Excel instance
How to control running Excel instance How to control running Excel instance
How to control running Excel instance
How to control running Excel instance
How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance How to control running Excel instance
How to control running Excel instance
How to control running Excel instance
 
How to control running Excel instance
How to control running Excel instance
 
-->