Lỗi microsoft visual basic cho đường dẫn ứng dụng/lỗi truy cập tệp

Xin chào các bạn, tôi mới làm quen với excel VBA và tôi đang gặp khó khăn trong việc khắc phục lỗi này. Mọi thứ đang hoạt động nhưng tôi không thể di chuyển tệp từ đường dẫn này sang đường dẫn khác

Lỗi thời gian chạy Excel '75' Lỗi truy cập đường dẫn/tệp

Mã VBA

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

 

Xin chào,

Mình cũng bị lỗi này từ khi cài Office 2003

Trong trường hợp của tôi, sự cố là do không có quyền tạo
tệp tạm thời.

Hãy để tôi giải thích

Thông báo lỗi tôi nhận được hơi khác so với thông báo lỗi của bạn, lỗi của tôi là “Lỗi truy cập “Đường dẫn/Tệp
. '\VB??. tmp'”. Lưu ý rằng dấu chấm đầy đủ, trong đường dẫn tệp,
cho biết thư mục hiện tại bị thiếu. Điều này có nghĩa là
đang cố gắng ghi vào thư mục gốc của ổ đĩa của thư mục
hiện tại.

Điều ban đầu tôi không biết là nó đang cố ghi vào ổ đĩa nào. Tôi
có thể đã nghĩ C. hoặc thư mục Windows Temp của tôi nằm ở đâu, nhưng
không.

Nó đang cố gắng tạo chúng cho L của chúng tôi. lái xe. Tôi không được phép
viết thư cho L. thư mục gốc ổ đĩa.

Câu hỏi đặt ra là tại sao nó lại cố gắng ghi nó vào ổ đĩa đó? . lái xe.
was that we use File Redirection under group policies to redirect all the
users “My Documents” folders to a sub-directory system on the L: drive.
Thao tác sao chép và dán giả định rằng nó có thể sử dụng thư mục gốc của
“Tài liệu của tôi” (có thể là thư mục L. drive) dưới dạng
không gian làm việc tạm thời. Điều này sẽ hoạt động tốt nếu “Tài liệu của tôi” nằm trên C.
lái xe.

Tôi đã được cấp quyền truy cập tập tin vào thư mục gốc của L. drive
giải quyết được sự cố của tôi. Tuy nhiên, vì lý do bảo mật, tôi không nghĩ rằng đó
có nghĩa là một giải pháp lâu dài. Nếu có ai có giải pháp tốt hơn, vui lòng cho
tôi biết.

Tôi cho rằng vấn đề này là do sơ suất của Microsoft. Họ nên
tốt hơn là ghi Tệp tạm thời vào thư mục Tạm thời của người dùng thay vì ghi vào
thư mục gốc hoặc vào một đường dẫn tương đối từ thư mục “Tài liệu của tôi”.

Hy vọng điều này sẽ hữu ích,
Thomas