MS Access VBA参考

问题描述 投票:0回答:1

我有这个数据库,它工作得很完美,但今天它开始讨厌我了。我开始收到编译错误:无法找到项目或库。我环顾四周,发现当在不同的计算机上使用前端时,在VBA和引用下,它缺少Microsoft Word 15.0对象库的引用。

我的电脑我检查了Microsoft Word 16.0对象库。如何才能在15.0和16.0的其他计算机上使用它?

这是代码

Private Sub cmd_LocateFile_Click()
On Error GoTo Error_Handler
Dim sFile As String
Dim sFolder As String
Dim ID As Long
Dim sTarget As String



sFile = FSBrowse("", msoFileDialogFilePicker, "All Files (*.*),*.*")
If sFile <> "" Then
    sFolder = ("\\aiowima23fp1\Ecological Sciences and Engineering\Cultural Resources\New - Cultural Resources Request Database") & "\" & sAttachmentFolderName & "\"
    If FolderExist(sFolder) = False Then MkDir (sFolder)
    ID = RequestID_FK  ' Set current record id.
sTarget = sFolder & CStr(ID) & "-" & GetFileName(sFile)
If CopyFile(sFile, sFolder & GetFileName(sTarget)) = True Then
        Me!FullFileName.Value = sTarget
    Else
    End If
End If

Error_Handler_Exit:
On Error Resume Next
Exit Sub

Error_Handler:
MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
       "Error Number: " & Err.Number & vbCrLf & _
       "Error Source: " & sModName & "\cmd_LocateFile_Click" & vbCrLf & _
       "Error Description: " & Err.Description & _
       Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
       , vbOKOnly + vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Sub
ms-access access-vba
1个回答
0
投票

在开发期间添加对Word的引用有利于能够使用强类型的单词对象,从而能够利用IntelliSense。但是,正如您所经历的那样,这些引用对版本控制是明智的。因此,我建议您在实现开发后删除对Word的引用。您还必须用Object替换所有与Word相关的类型,即使用后期绑定。这使得应用程序在版本控制方面更加健壮。

您可以使用此代码片段获取已打开的现有Word实例或打开一个新实例,而不引用任何Word DLL。

Public Function GetWordApplication() As Object
    'Gets an active Word application or opens a new Word instance.
    'Raises Error No. 8 if word cannot be opened.

    On Error Resume Next
    'Find existing instance of Word
    Set GetWordApplication = GetObject(, "Word.Application")
    If Err.Number <> 0 Then 'Not found, create new instance.
        Set GetWordApplication = CreateObject("Word.Application")
    End If

    'Following code is optional. You can instead test for Nothing at the call site
    On Error Goto 0
    If GetWordApplication Is Nothing Then
        Err.Raise 8, "YourApp.GetWordApplication", "Word could not be opened."
    End If
End Function
© www.soinside.com 2019 - 2024. All rights reserved.