Path/File Access Error 75 trying to copy file

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to come up with a routine that allows a user to browse to a file and then copy it to the same path as the active workbook - this is what I have so far;

Code:
Dim SourceFile, DestinationFile

SourceFile = Application.GetOpenFilename(FileFilter:="PDF Files (*.pdf), *.pdf", Title:="Select exisiting File")
DestinationFile = ThisWorkbook.Path
FileCopy SourceFile, DestinationFile

With the above though I keep getting an error 75, Path/File Access Error and it fails on this line;

Code:
FileCopy SourceFile, DestinationFile

I can manually copy it no problem, so what's the issue?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
ThisWorkbook.Path only returns the path. So you'll need to include the filename. Try...

Code:
DestinationFile = ThisWorkbook.Path & "\" & Mid(SourceFile, InStrRev(SourceFile, "\") + 1)

I would suggest you amend your code as follows...

Code:
Dim SourceFile As String
Dim DestinationFile As String


SourceFile = Application.GetOpenFilename(FileFilter:="PDF Files (*.pdf), *.pdf", Title:="Select exisiting File")
If SourceFile = "False" Then Exit Sub


DestinationFile = ThisWorkbook.Path & "\" & Mid(SourceFile, InStrRev(SourceFile, "\") + 1)


FileCopy SourceFile, DestinationFile

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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