如统计分析函数里的宏,加载后用Excel可以直接调用,用录制能跟踪出来,但在程序里不能运行。
Application.Run "xxxx!yyyy",......
用Excel对象或者Ole都不行。
???

解决方案 »

  1.   

    将录制的代码直接拷到程序,在每行代码的range,selection前加上xlsheet,xlapp等
      

  2.   

    在VB里执行c:\22.doc中的test1宏,如下:Dim wdApp
    Dim doc
    Set wdApp = CreateObject("word.application")
    wdApp.Visible = True
    Set doc = wdApp.Documents.Open("c:\22.doc")
    doc.Application.Run "test1"
      

  3.   

    TO 1楼 2楼:不行,EXCEL提供的统计分析宏代码是加密的,看不了,只知道接口,录制的宏代码就是
    Application.Run "XXXXX.xla!YYYY",,.....
    但是我试了,用EXCEL.APPLICATION 对象或者用OLE对象都不能运行,能找到对应的xla文件,应该是封装的宏代码,在EXCEL打开后不能浏览的,需要密码。
      

  4.   

    可以试试在EXCEL菜单-->工具-->加载宏里加载数学统计分析函数。
    里面的函数都可以用,但是用代码调用不了
      

  5.   

    HOWTO: Call Microsoft Excel Macros That Take Parameters
    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. 
      

  6.   

    TO 楼上的,你说的方法也是调用一般的宏。
    我想知道的是如何调用EXCEL里提供的一些内置的宏的方法。
    像我说的数学统计分析函数,实际上就是一个XXXX.XLA文件。录制宏发现是通过"!方法"来实现的。录制的宏代码就是如下:
    Application.Run "XXXXX.xla!YYYY",,.....但是该代码在程序里通过EXCEL对象是没有办法执行的。当然,如果写在自定义宏里,通过运行宏可以运行。但是存在很多参数的问题,有没有办法直接通过EXCEL对象,比如APPLICATION来直接运行该宏的方法,这样才容易在程序里控制,比如参数什么的。如果解决,分不是问题。