Excel run time error '75' Path/file access error

MajorFudge69

New Member
Joined
Nov 12, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi Guys, i'm very new to excel VBA and i'm having troubles to resolve this error. Everthing is working but i can't move the file from one path to the other

Excel run time error '75' Path/file access error​

VBA Code:
Sub Import_All()

Dim fPath  As String, fName As String, fPathDone As String
Dim LR As Long, NR As Long
Dim LC As Long
Dim wbData As Workbook, wsMaster As Worksheet
Dim StartCell As Range
Dim wsData As Worksheets
Dim LRMaster As Long
Dim lCopyLastRow As Long
Dim lDestLastRow As Long

'Setup

    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    
    Set wsMaster = ThisWorkbook.Sheets("OR MANAGEMENT - INPUT")
    
    With wsMaster
   
   LR = wsMaster.Cells.Find(What:="*", After:=wsMaster.Range("E10"), LookIn:=xlFormulas, _
           Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
           MatchCase:=False).Row

   LC = wsMaster.Cells.Find(What:="*", After:=wsMaster.Range("E10"), LookIn:=xlFormulas, _
           Lookat:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, _
           MatchCase:=False).Column

   Set GetLastNonEmptyCellOnWorkSheet = wsMaster.Cells(LR, LC)
   
'Pasta
Do
    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = DefaultFolder
        .Title = " Selecione a Pasta com os ficheiros a importar | MOAI Consulting"
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            fPath = .SelectedItems(1) & "\"
        Exit Do
        Else
            If MsgBox("Não foi selecionado nenhum ficheiro, deseja cancelar?", _
                vbYesNo) = vbYes Then Exit Sub
        End If
    End With
    
 Loop
 
fPathDone = fPath & "Imported"     'remember final \ in this string
    On Error Resume Next
        MkDir fPathDone                 'creates the completed folder if missing
    On Error GoTo 0
    fName = Dir(fPath & "*.xlsx*")       'listing of desired files, edit filter as desired

'Import a sheet from found files
    Do While Len(fName) > 0
        If fName <> ThisWorkbook.Name Then              'don't reopen this file accidentally
            Set wbData = Workbooks.Open(fPath & fName) 'Open file
               
  '1. Find last used row in the copy range based on data in column A
  lCopyLastRow = wbData.Worksheets("Sheet1").Cells(wbData.Worksheets("Sheet1").Rows.Count, "B").End(xlUp).Row
    
  '2. Find first blank row in the destination range based on data in column A
  'Offset property moves down 1 row
  lDestLastRow = wsMaster.Cells(wsMaster.Rows.Count, "E").End(xlUp).Offset(1).Row

  '3. Copy & Paste Data
  wbData.Worksheets("Sheet1").Range("B3:J" & lCopyLastRow).Copy
    wsMaster.Range("E10").PasteSpecial
    
Name fPath & fName As fPathDone & fName           'move file to IMPORTED folder
        End If
        fName = Dir                                       'ready next filename
    Loop
End With

ErrorExit:    'Cleanup
    ActiveSheet.Columns.AutoFit
    Application.DisplayAlerts = True         'turn system alerts back on
    Application.EnableEvents = True          'turn other macros back on
    Application.ScreenUpdating = True        'refreshes the screen
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You've got comments about final \ and as I see there is not there
VBA Code:
fPathDone = fPath & "Imported"     'remember final \ in this string
I think it should be:
VBA Code:
fPathDone = fPath & "Imported\"     'remember final \ in this string
Just guessing, you did not say which line generates error.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top