0

I get a Run-time error '52' (Bad file name or number) on the FileCopy line. The string variables seem to have the correct file location and the files open up fine when done manually. Not sure what I'm doing wrong here.

Sub copyOver()
Dim sourceFile, destFile As String
Dim fle As Variant

destFile = Sheet11.Range("A1").Value
For Each fle In Sheet11.Range("A2:A5")
    sourceFile = fle.Value
    FileCopy sourceFile, destFile
Next fle

End Sub

1 Answer 1

2

You need to pass full paths (including filename) for both sourceFile and destFile

Sign up to request clarification or add additional context in comments.

5 Comments

I did. destFile is something like C:/folder1 and sourceFile is something like C:/folder1/text.doc
C:/folder1 or C:\folder1 ? Just do a dir in your code to test if the filepath provided by you is correct.
Full path means path and filename, not just a destination directory: updated my answer to clarify.
@cyboashu I meant C:\folder1. And it's 100% correct. I can paste the exact file path into Windows Explorer and the file opens with no problems.
@TimWilliams ahh I see what you meant. Fixed it great. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.