要打开 AppPath & "\Book.xls" 这个文件,在程序应该怎么写?
调用什么API函数?

解决方案 »

  1.   

    如果是打开并用代码操作Excel,可以这样:引用Excel("工程"/"引用"/Microsoft Excel Object X.0 Library)Private Sub Command1_Click()
        Dim xlApp As New Excel.Application    '定义并创建EXCEL对象    Dim xlBook As Excel.Workbook    '创建工作簿
        Dim xlSheet As Excel.Worksheet    xlApp.Visible = True    '让Excel可见
        Set xlBook = xlApp.Workbooks.Open(App.Path & "\Book.xls")   '打开Excel文件
        Set xlSheet = xlBook.Sheets(1)  
        
    '    xlBook.PrintPreview  '打印预览'    xlBook.Close True   '保存
    '    xlApp.Quit  '关闭Exel
        Set xlBook = Nothing
        Set xlApp = NothingEnd Sub
      

  2.   

    如果是仅仅打开文件,可以用Shell函数 或ShellExecute API函数:Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Const SW_SHOWNORMAL = 1 private Sub Command1_Click()
        ShellExecute 0, "open", App.Path & "\Book.xls", "", "", SW_SHOWNORMAL
    End Sub