我创建了一个VBA访问应用程序,通过执行一次扫描来查找文件夹中的PDF文件,以获取根文件夹中的所有子文件夹。然后进行另一次扫描以收集所有文件名并将其与所选文件名进行比较。然后我们使用以下代码在找到文件时打开文件:
Private Sub Command132_Click()
On Error GoTo Err_Command132_Click
Dim rootFolder As String
Dim subFolder As String
Dim fileSpec As String
Dim filename As String
Dim foundfile As String
Dim filepath As String
Dim subfolders() As String
Dim co As String
Dim intSubFolderCount As Integer
rootFolder = "T:\Scanned Work Orders (Archives)\"
subFolder = Dir(rootFolder & "*.*", vbDirectory)
'*** Get subfolders in array ***
While subFolder <> ""
If subFolder <> "." And subFolder <> ".." Then
ReDim Preserve subfolders(intSubFolderCount)
subfolders(intSubFolderCount) = subFolder
intSubFolderCount = intSubFolderCount + 1
Debug.Print subFolder
End If
subFolder = Dir()
Wend
'*** Loop over array and find files ***
For intSubFolderCount = 0 To UBound(subfolders)
fileSpec = Trim(Me.Combo_History) & "*.pdf"
co = subfolders(intSubFolderCount)
filename = Dir(rootFolder & subfolders(intSubFolderCount) & "\" & fileSpec)
Do While filename <> ""
filepath = rootFolder & subfolders(intSubFolderCount)
foundfile = filepath & "\" & filename
Application.FollowHyperlink foundfile
GoTo Exit_Command132_Click
Exit Do
Loop
Next intSubFolderCount
MsgBox "No Scanned work order found for " & Me.Combo_History & "!"
Exit_Command132_Click:
Exit Sub
Err_Command132_Click:
Select Case Err.Number
Case 52
MsgBox "No Scanned work order found for " & Me.Combo_History & "!"
Case Else
MsgBox Err.Number & "-" & Err.Description
End Select
End Sub
但在我办公室的某些计算机上,他们收到此错误消息:
“某些文件可能包含病毒或对您的计算机有害。 重要的是要确保此文件来自可信赖的来源。
您要打开此文件吗?“
有可能压制这个吗?我们正在运行Windows 7专业版。
答案 0 :(得分:0)
这是一项Windows功能。微软有KB在这里删除它。 https://support.microsoft.com/en-us/kb/925757
可以使用VBA更改注册表设置,但请先按照KB说明操作,以确保它能解决您的问题。