积极答复者
about excel activex

问题
-
_Application ExcelApp; Workbooks wbsMyBooks; _Workbook wbMyBook; Worksheets wssMysheets; _Worksheet wsMysheet; Range rgMyRge; //创建Excel 2000服务器(启动Excel) if (!ExcelApp.CreateDispatch("Excel.Application",NULL)) { AfxMessageBox("创建Excel服务失败!"); exit(1); } //利用模板文件建立新文档 wbsMyBooks.AttachDispatch(ExcelApp.GetWorkbooks(),true); wbMyBook.AttachDispatch(wbsMyBooks.Add(_variant_t("g:\\exceltest\\MyTemplate.xlt"))); 在最后面两行是新建一个EXCEL文件, 假设我EXCEL已经打开了一个文件,我想在已经打开的文件上操作,这时怎么处理? in english: the end of code is add a new excel file , if I had opened a file and process the file , how to get opened file?
这个问题困扰我很长时间了,希望在这里能解决
在vc6里面做个ACTIVEX控件DLL,源代码是这样的
Excel.AddNewFile(); // 建一个空文件
Excel.SetVisible(true); // 设置可见在vba里面这么调用:
Dim kka As New Activett
Sub aff()
kka.AddSheetEnd Sub
这里是在新建一个文件里面操作,如果要在当前WORKBOOK操作
afx_msg void AddSheet(ThisWorkBook);
Cexcel Excel;
Excel.SetVisible(true); // 设置可见
Excel.CopySheet(Excel.SelectSheet(1)); Dim kka As New Activett在vba里面这么调用:
Sub aff()
Call kka.AddSheet(thisworkbooks)
End Sub运行提示方法错误 该怎么办呀? 各位高手指点下,谢谢!
答案
-
参数类型换成IDispatch*看看
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已标记为答案 Honny_yeyh 2011年2月15日 5:11
- 已标记为答案 宋翔Moderator 2011年4月10日 17:30
全部回复
-
这个问题困扰我很长时间了,希望在这里能解决
在vc6里面做个ACTIVEX控件DLL,源代码是这样的
Excel.AddNewFile(); // 建一个空文件
Excel.SetVisible(true); // 设置可见在vba里面这么调用:
Dim kka As New Activett
Sub aff()
kka.AddSheetEnd Sub
这里是在新建一个文件里面操作,如果要在当前WORKBOOK操作
afx_msg void AddSheet(ThisWorkBook);
Cexcel Excel;
Excel.SetVisible(true); // 设置可见
Excel.CopySheet(Excel.SelectSheet(1)); Dim kka As New Activett
在vba里面这么调用:
Sub aff()
Call kka.AddSheet(thisworkbooks)
End Sub运行提示方法错误 该怎么办呀? 各位高手指点下,谢谢!
- 已移动 lucy-liu 2011年2月14日 10:57 与c++无关 (发件人:Visual C++)
- 已合并 Sheng Jiang 蒋晟Moderator 2011年2月22日 2:52
-
其实看这个代码也可以的:
_Application ExcelApp;
Workbooks wbsMyBooks;
_Workbook wbMyBook;
Worksheets wssMysheets;
_Worksheet wsMysheet;
Range rgMyRge; //创建Excel 2000服务器(启动Excel)
if (!ExcelApp.CreateDispatch("Excel.Application",NULL))
{
AfxMessageBox("创建Excel服务失败!");
exit(1); } //利用模板文件建立新文档
wbsMyBooks.AttachDispatch(ExcelApp.GetWorkbooks(),true);
wbMyBook.AttachDispatch(wbsMyBooks.Add(_variant_t("g:\\exceltest\\MyTemplate.xlt")));
在最后面两行是新建一个EXCEL文件, 假设我EXCEL已经打开了一个文件,我想在已经打开的文件上操作,这时怎么处理?
- 已编辑 lucy-liu 2011年2月8日 7:49 为了更美观
-
_Application ExcelApp;
Workbooks wbsMyBooks;
_Workbook wbMyBook;
Worksheets wssMysheets;
_Worksheet wsMysheet;
Range rgMyRge; //创建Excel 2000服务器(启动Excel)
if (!ExcelApp.CreateDispatch("Excel.Application",NULL))
{
AfxMessageBox("创建Excel服务失败!");
exit(1); } //利用模板文件建立新文档
wbsMyBooks.AttachDispatch(ExcelApp.GetWorkbooks(),true);
wbMyBook.AttachDispatch(wbsMyBooks.Add(_variant_t("g:\\exceltest\\MyTemplate.xlt"))); //得到Worksheets
wssMysheets.AttachDispatch (wbMyBook.GetWorksheets(),true); //得到sheet1
- 已编辑 lucy-liu 2011年2月8日 7:50 为了格式更美观
-
Hi Honny_yeyh,
我编辑了下你的帖子,增加可读性。请不要介意。
谢谢,
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Hi Honny_yeyh,
您这问题是有关office的,我建议您到microsoft 的英文论坛:http://social.answers.microsoft.com/Forums/en-US/category/officeexcel发帖,那个论坛里有这方面的专家,他们会尽力帮您解决问题。
谢谢您的理解!
谢谢,
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
_Application ExcelApp;
Workbooks wbsMyBooks;
_Workbook wbMyBook;
Worksheets wssMysheets;
_Worksheet wsMysheet;
Range rgMyRge; //创建Excel 2000服务器(启动Excel)
if (!ExcelApp.CreateDispatch("Excel.Application",NULL))
{
AfxMessageBox("创建Excel服务失败!");
exit(1); } //利用模板文件建立新文档
wbsMyBooks.AttachDispatch(ExcelApp.GetWorkbooks(),true);
wbMyBook.AttachDispatch(wbsMyBooks.Add(_variant_t("g:\\exceltest\\MyTemplate.xlt")));
在最后面两行是新建一个EXCEL文件, 假设我EXCEL已经打开了一个文件,我想在已经打开的文件上操作,这时怎么处理?
in english: the end of code is add a new excel file , if I had opened a file and process the file , how to get opened file?
- 已合并 Sheng Jiang 蒋晟Moderator 2011年2月22日 2:51
-
这个问题困扰我很长时间了,希望在这里能解决
在vc6里面做个ACTIVEX控件DLL,源代码是这样的
Excel.AddNewFile(); // 建一个空文件
Excel.SetVisible(true); // 设置可见在vba里面这么调用:
Dim kka As New Activett
Sub aff()
kka.AddSheetEnd Sub
这里是在新建一个文件里面操作,如果要在当前WORKBOOK操作
afx_msg void AddSheet(ThisWorkBook);
Cexcel Excel;
Excel.SetVisible(true); // 设置可见
Excel.CopySheet(Excel.SelectSheet(1)); Dim kka As New Activett在vba里面这么调用:
Sub aff()
Call kka.AddSheet(thisworkbooks)
End Sub运行提示方法错误 该怎么办呀? 各位高手指点下,谢谢!
-
参数类型换成IDispatch*看看
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已标记为答案 Honny_yeyh 2011年2月15日 5:11
- 已标记为答案 宋翔Moderator 2011年4月10日 17:30