0

Getting Run-time error when i try to move a file. The file is in my documents, and within documents there is a folder called "Archive", which is where im trying to move. As you can see in the last part of the code, I've added the text "Archive" to the file path so that there is a new file path. Can someone explain why this error occurs?

Public wb As Workbook
Public ws As Worksheet
Public SourceFile_Location
Public srcWB As String
Public srcWB_sheet As String
Sub Full_Code()
Call DataFile
Call test2
End Sub
Sub DataFile()

SourceFile_Location = Dir("C:\Users\Asad\Documents\*.xl??")

Set wb = Workbooks.Open(SourceFile_Location)
Set ws = wb.Worksheets(1)

srcWB = wb.Name
srcWB_sheet = ws.Name

End Sub
Sub test2()
wb.Activate

fpath = ActiveWorkbook.Path
fpathnew = fpath & "\Archive"

ActiveWorkbook.Close

Name fpath As fpathnew & "\" & srcWB ***<- this is where my error is***

End Sub
jacouh
  • 8,473
  • 5
  • 32
  • 43
akh275
  • 15
  • 5
  • You have `Sub test2()` and `Sub Full_Code()` with only one `End Sub`. – Toni May 13 '21 at 20:17
  • You may want to read up on [Path/File access error (Error 75)](https://learn.microsoft.com/en-us/office/vba/Language/Reference/user-interface-help/path-file-access-error-error-75). Having said that, check the values of `fpathnew` and `srcWB`. And yes, one more thing... Definitely read [to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). Your code can be made more robust. ;) – Siddharth Rout May 13 '21 at 20:23
  • 1
    here is why the error occurs: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/path-file-access-error-error-75 – sous2817 May 13 '21 at 20:24
  • Name fpath & "\" & srcWB As fpathnew & "\" & srcWB would solve the problem. – jacouh May 13 '21 at 20:27
  • Please edit your question to get an answer to describe what you need, timestamp can be 158888544 in seconds, or 20210513 date of today, before file name or after file name ...? – jacouh May 13 '21 at 20:36
  • Sorry, StackOverFLow community will not accept this kind of work, please make your own test before. And +edit your question. – jacouh May 13 '21 at 20:53

0 Answers0