如统计分析函数里的宏,加载后用Excel可以直接调用,用录制能跟踪出来,但在程序里不能运行。
Application.Run "xxxx!yyyy",......
用Excel对象或者Ole都不行。
???
Application.Run "xxxx!yyyy",......
用Excel对象或者Ole都不行。
???
解决方案 »
- vba 拼字符串
- 怎么样读取包含中文的字符串?????
- 当窗体内控件太多时,如何使用滚动条形成网页效果的滚动
- vb6如何将ACCESS数据表里全部数据以TXTl格式保存到本地计算机
- 怎样把字符串“123”转化成整数123
- 开发一个软件时,由于功能模块很多,是分开几个工程,如何在第一个工程里打开第二个工程的窗口
- 请问该如何在crystal report中新建一个detail啊?
- Picturebox控件问题!!!!(你说简单,进来拿分;我说不简单,只好送分!!)
- 请问如何实现类似于解霸的双声道同时输出,左声道或右声道的声音?
- VB操作数据库用什么控件?我刚学
- 高手请进,怎么样使用GDI+在内存中转换图片类型?
- 在VB中如何实现点击一个BUTTON显示帮助文件?
Dim doc
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set doc = wdApp.Documents.Open("c:\22.doc")
doc.Application.Run "test1"
Application.Run "XXXXX.xla!YYYY",,.....
但是我试了,用EXCEL.APPLICATION 对象或者用OLE对象都不能运行,能找到对应的xla文件,应该是封装的宏代码,在EXCEL打开后不能浏览的,需要密码。
里面的函数都可以用,但是用代码调用不了
The information in this article applies to:
Microsoft Excel 2000
Microsoft Visual Basic Learning Edition for Windows 5.0
Microsoft Visual Basic Learning Edition for Windows 6.0
Microsoft Visual Basic Professional Edition for Windows 5.0
Microsoft Visual Basic Professional Edition for Windows 6.0
Microsoft Visual Basic Enterprise Edition for Windows 5.0
Microsoft Visual Basic Enterprise Edition for Windows 6.0
Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
Microsoft Visual Basic for Applications 5.0
Microsoft Excel 2002
Microsoft Excel 97 for Windows
This article was previously published under Q153307
SUMMARY
Using Automation, you can manipulate Microsoft Excel. It is possible to call macro procedures that are stored in Microsoft Excel Workbooks by using the Run method of the Microsoft Excel Application object. Microsoft Excel macro procedures that take parameters cause a slight change in the syntax. Included below is a code sample showing how to call a Microsoft Excel macro procedure from Visual Basic.
MORE INFORMATION
Step-by-Step Example
Start a new Project in Visual Basic. Form1 is created by default.
Place a CommandButton on Form1.
In the General Declarations section of Form1, enter this code:
Option Explicit Private Sub Command1_Click()
Dim oExcelApp As Object ' Create a reference to the currently running excel application
Set oExcelApp = GetObject(, "Excel.application")
' Make the Excel Application Visible.
oExcelApp.Visible = True
' Run the excel procedure
oExcelApp.run "proc", "David", 30
End Sub
Start Microsoft Excel. Book1 is created by default.
Add a new module to the workbook.For Excel 5.0 and 7.0: From the Insert menu, choose Macro, and select the Module Option. This will give you a new module sheet, Module1.For Excel 97 and later: Press ALT+F11 to start the Visual Basic Editor. Click Module on the Insert menu.
In Module1, type the following code:
Sub Proc(sParam1 As String, iParam2 As Integer)
MsgBox sParam1 & " is " & iParam2 & " Years Old"
End Sub
Leave the workbook open in Microsoft Excel and switch to your project in Visual Basic.
From Visual Basic, press F5 to run the project. Click the command button, and you should see a dialog box appear with the text "David is 30 years old" in it.
我想知道的是如何调用EXCEL里提供的一些内置的宏的方法。
像我说的数学统计分析函数,实际上就是一个XXXX.XLA文件。录制宏发现是通过"!方法"来实现的。录制的宏代码就是如下:
Application.Run "XXXXX.xla!YYYY",,.....但是该代码在程序里通过EXCEL对象是没有办法执行的。当然,如果写在自定义宏里,通过运行宏可以运行。但是存在很多参数的问题,有没有办法直接通过EXCEL对象,比如APPLICATION来直接运行该宏的方法,这样才容易在程序里控制,比如参数什么的。如果解决,分不是问题。