jardenp
Active Member
- Joined
- May 12, 2009
- Messages
- 373
- Office Version
- 2019
- 2016
- 2013
- 2011
- 2010
- Platform
- Windows
I have a script that works fine on my machine (Win 7, Office 2010) but not on another machine (Win 10, Office 2010). I get a runtime error 70 permission denied when it tries to copy the file at the end of the script portion below. The other user can read/write/delete in all folders in use. From another post (here) I tried to switch
to
but that threw an error on the next line:
This is a script being used in a userform. "Entry" is an global integer variable defined in another sub.
My first thought is that it must be a reference issue between Win 7 and Win 10. Is there a reference I should check or uncheck in my VBE?
Thanks!
VBA Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
VBA Code:
Set oFSO = CreateObject("VBScript.RegExp")
VBA Code:
Set oFolder = oFSO.GetFolder(FolderPath)
This is a script being used in a userform. "Entry" is an global integer variable defined in another sub.
My first thought is that it must be a reference issue between Win 7 and Win 10. Is there a reference I should check or uncheck in my VBE?
Thanks!
VBA Code:
Private Sub TripScanClick()
Dim FolderPath As String, path As String, count As Integer
FolderPath = "S:\XXX\Destination Folder"
path = FolderPath & "\*"
Filename = Dir(path)
Do While Filename <> ""
count = count + 1
Filename = Dir()
Loop
If count = 0 Then
MsgBox "No files were found in the target folder " & path
Exit Sub
ElseIf count > 1 Then
MsgBox "More than one file was found in the target folder " & path & ". Please make sure the only file in the folder is the scan for this trip."
Exit Sub
End If
'Rename File
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim oFileName As String
Dim NewUnitFileName As String
NewUnitFileName = "\" & Me.Controls("TractorNum_TB" & Entry) & "- Odom " & Me.Controls("StartOdom_TB" & Entry) & "-" & Me.Controls("EndOdom_TB" & Entry) & " Trip Start Date " & Format(Me.Controls("TripStartDate_TB" & Entry), "yyyy-mm-dd") & ".pdf"
Dim NewPayrollFileName As String
NewPayrollFileName = "\" & Me.Controls("DivEntry_CB" & Entry) & "-" & Me.Controls("BillingGroup_CB" & Entry) & "-" & Left(Me.Controls("DriverName_CB" & Entry), 3) & "," & Mid(Me.Controls("DriverName_CB" & Entry), InStr(1, Me.Controls("DriverName_CB" & Entry), ",") + 2, 1) & "-" & Me.Controls("TractorNum_TB" & Entry) & "-" & Format(Me.Controls("TripStartDate_TB" & Entry), "yyyy-mm-dd") & ".pdf"
Dim UnitFilesDir As String
UnitFilesDir = "S:\XXX\Unit Trip Scans"
Dim TripArchiveDir As String
TripArchiveDir = "S:\XXX\Trip Sheet Archive"
Dim TripWeeklyFolderDir As String
TripWeeklyFolderDir = "S:\XXX\Trip Sheet Weekly Folders"
Dim PayrollByDivisionDir As String
PayrollByDivisionDir = "S:\XXX\Payroll by Division"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(FolderPath)
'kill thumbs.db if it's there
If Dir(FolderPath & "\thumbs.db") <> "" Then
SetAttr FolderPath & "\thumbs.db", vbNormal
Kill FolderPath & "\thumbs.db"
End If
For Each oFile In oFolder.Files
oFileName = oFile.Name
Next oFile
'Copy file to Archive
oFSO.CopyFile FolderPath & "\" & oFileName, _
TripArchiveDir & NewPayrollFileName