ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   AttachDispatch? (https://www.excelbanter.com/excel-programming/337571-attachdispatch.html)

[email protected]

AttachDispatch?
 
Hi,


I scoured the net (including newsgroups) for this info, and nothing I
found worked. Everything had to be heavily modified just to compile,
and the result was still non-functional. Just letting you know I did
my homework before coming here :).

I'm trying to export some data directly to Excel format. I'm using
Excel (2002) on VC++ on an XP system, but would like this to work on as
many versions of Excel and Windows as possible as this will be part of
a shrink-wrapped app.

I was able to get an example from Microsoft's site (which didn't
compile) and modified it. I used xlen32.olb for my type library as I
don't have excel*.olb, and mapped some members (_Application -
Application, GetWorkbooks() - Workbooks(), etc...). But now, I'm
having a problem with AttachDispatch(). Here's the relevant code with
error checking removed for brevity:

Application excel;
excel.CreateDispatch("Excel.Application");
COleVariant covZero((long)0);
COleVariant covDisp = excel.Workbooks(covZero);
Workbooks wbs;
wbs.AttachDispatch(covDisp);

AttachDispatch expects an LPDISPATCH parameter. However, Workbooks
returns a COleVariant. How do I convert from one to the other, or am I
supposed to? GetWorkbooks() -- which should return LPDISPATCH -- is
not a member of Application.

Any help would be greatly appreciated. Even if you can't find what's
wrong with the above, I'll accept links to sites with more info,
snippets of worksheet creation in Excel, etc...


Thanks in Advance.



All times are GMT +1. The time now is 10:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com