谁知道怎样在VB调用已经存在的EXCEL表格,其余的操作就完全在EXCEL中完成知道的朋友给一个实例!拜托了

来源:百度知道 编辑:UC知道 时间:2024/06/05 09:51:35

先在工程--引用中选中microsoft excel,然后用下列代码可以打开电子表格文件:
Dim mxlApp As Excel.Application
Dim mxlBook As Excel.Workbook
Dim mxlSheet As Object
Dim sSource As String

Set mxlApp = New Excel.Application
Set mxlApp = CreateObject("Excel.Application")
sSource = "路径及文件名"
mxlApp.Visible = True
Set mxlBook = mxlApp.Workbooks.Open(sSource)
Set mxlSheet = mxlBook.Worksheets(1)

方法一:
用 OLE 控件试试?

方法二:
用API函数,直接打开Excel文件
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Function StartDoc(DocName As String) As Long
Dim Scr_hDC As Long

Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute