Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 431
- Office Version
- 365
- Platform
- Windows
- Mobile
Please can somebody help me to understand why the Dir function says Runtime Error 91
VBA Code:
Private Sub OpenFolder_Click()
Dim SourcePath As String
Dim SubPath As String
Dim strFolder As String
Dim MyPath As String
Dim PDFFName As String
Dim CmbData
CmbData = Split(Me.OpenDrawing.Value, "-")
CmbData(0) = Replace(CmbData(0), "-", "")
MyPath = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"
SourcePath = "\\dc01\Company\R&D\Drawing Nos"
SubPath = CStr(Val(Int(CmbData(0) / 50) * 50 + 1) & "-" & Int(CmbData(0) / 50 + 1) * 50)
PDFFName = OpenDrawing.Value
strFolder = SourcePath & "\" & SubPath & "\" & Int(CmbData(0))
ActiveWorkbook.FollowHyperlink Address:=strFolder, NewWindow:=True
End Sub
Private Sub Fill_DrNumbers_Click()
Dim myfso As FileSystemObject, myfolder As Object, myFile As Object, Dir As Object
Dim SourcePath As String
Dim SubPath As String
Dim PdfFolder As Folder
Dim PdfFile As String
Dim MyPath As String
Dim PDFFName As String
Dim CmbData
CmbData = Split(Me.OpenDrawing.Value, "-")
CmbData(0) = Replace(CmbData(0), "-", "")
MyPath = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"
SourcePath = "\\dc01\Company\R&D\Drawing Nos"
SubPath = CStr(Val(Int(CmbData(0) / 50) * 50 + 1) & "-" & Int(CmbData(0) / 50 + 1) * 50)
Me.PdfDrawingList.Clear
Set myfso = New Scripting.FileSystemObject
Set myfolder = myfso.GetFolder(SourcePath & "\" & SubPath & "\" & Int(CmbData(0)))
Set myFile = Dir(myfolder & ".Pdf")
If Right(myfolder, 1) <> "\" Then
myfolder = myfolder & "\"
End If
Do While Len(myFile) > 0
If Right(myFile, 3) = "pdf" Then
Me.PdfDrawingList.AddItem myFile.Name
End If
myFile = Dir
Loop
End Sub