【发布时间】:2010-09-01 13:33:04
【问题描述】:
我有一个 Excel 2007 工作簿,其中包含一个 ODBC 数据连接(到 FoxPro,如果这很重要的话)。连接设置为“打开文件时刷新数据”。
当我进入文件资源管理器并打开工作簿时,数据会按应有的方式填充到电子表格中。但是,当我在 Access VBA 中执行打开工作簿的函数时,不会填充来自 ODBC 连接的数据。
为什么打开工作簿的方式会有所不同?更重要的是,当通过 Access VBA 打开工作簿时,如何获取要填充的数据?
这是打开工作簿的 Access VBA 代码:
Public Sub Subform_cmdOpenFile_Click(frm As Form)
Dim rs As Recordset
Dim ftiSuperclass As FilingTemplateInterface
Set rs = frm.RecordsetClone
If (rs.BOF Or rs.EOF) Then GoTo PROC_EXIT
Set ftiSuperclass = New FilingTemplateInterface
ftiSuperclass.ShowWorkbook rs!Directory & frm!Filename
PROC_EXIT:
On Error Resume Next
rs.Close
Set rs = Nothing
ftiSuperclass.QuitExcel
Set ftiSuperclass = Nothing
Exit Sub
PROC_ERROR:
Resume PROC_EXIT
End Sub
Friend Sub ShowWorkbook(strFilename As String)
Dim fso As New Scripting.FileSystemObject
Dim appExcel As New Excel.Application
appExcel.Workbooks.Open Filename:=strFilename, AddToMRU:=True
appExcel.visible = True
Set appExcel = Nothing
End Sub
【问题讨论】: