vba - 如何在不需要 Microsoft Office 16.0 对象库的情况下使用后期绑定
问题描述
如果Microsoft Office 16 Object Library
在reference
. 我的问题是,我该如何使用late binding
,这样我就不必从参考列表中添加 Microsoft Office 16 对象库。
在我的启动表格上,我有:
Private Sub Form_Load()
On Error Resume Next
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT CustomerName FROM tblCustomers")
If Err.Number <> 0 Then
MsgBox "Back-end data Not found: " & Err.Number & " " & Err.Description & " Please locate the data
file!", , "Data file not found"
Call AttachBackEndFile
End If
rs.Close
Set rs = Nothing
DoCmd.Close acForm, "frmStartUp"
DoCmd.OpenForm "frmMain"
End Sub
打开文件对话框的功能:
Public Function AttachBackEndFile() As Boolean
On Error GoTo 0
Dim oFileDialog As FileDialog
Dim result As VbMsgBoxResult
Set oFileDialog = FileDialog(msoFileDialogFilePicker)
oFileDialog.show
If oFileDialog.SelectedItems.Count = 1 Then
result = RelinkTables(oFileDialog.SelectedItems(1))
If result = vbCancel Then
AttachBackEndFile = False
End If
AttachBackEndFile = True
Else
AttachBackEndFile = False
End Sub
谢谢!