PDA

View Full Version : Solved: openfiledialog run-time error 75 path/file Access Error



G_Drifter
07-04-2011, 11:39 PM
Hi,

I'm trying to copy files selected in the openfiledialog to c:\Rawdata.

The code below causes the Run-time error 75.


Public Sub GetFiles()
Dim fDialog As Office.FileDialog
Dim fso As New FileSystemObject
Dim Path As String
Dim Filename As String
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog
.AllowMultiSelect = True
.Title = "Please select one or more files"
.Filters.Clear
.Filters.Add "CSM Files", "*.TXT"
Path = "C:\RawData"

If .Show = True Then
For Each varFile In .SelectedItems
Filename = varFile
FileCopy varFile, Path
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub



From what i've read on-line the error relates to permisions or lack of source file. The file clearly exists and I can copy and paste the file to the destination directory from within the open file dialog window so I can't see a permissions issue. I'm very new to VBA, and I'm probably missing something that should be obvious.:banghead:

Any advice much appreciated

hansup
07-05-2011, 08:59 PM
The FileCopy command expects a file name as the destination, but you're giving it a folder instead.

In this example from my system, the first command triggers that same error #75. The second works without error.
FileCopy "C:\Access\wip\temp.bas", "C:\Access"
FileCopy "C:\Access\wip\temp.bas", "C:\Access\temp.bas"

G_Drifter
07-05-2011, 10:02 PM
Thankyou very much Hansup.

As I'm sellecting 4 files in the dialog box it sounds like I'll
need to strip off the filename from the Source string, store it as a var
and append it to the Destination path something like

FileCopy "C:\TestData\Test.txt", "C:\Rawdata\" & Filename

I'll give this a try.

Many thanks

G_Drifter
07-05-2011, 10:20 PM
Hansup, This works perfectly. You've just washed away hours of frustration :-)

Thankyou very much