0

Borrowed the code and tweaked. Everything worked fine until strPath2 only receives filename instead of the entire file path. After searching there is surprisingly no answer.

I basically want to let Dir find any file that contain the word "Hello" in its filename. The start and the end of the filename varies. Is there any function/method that returns the full directory path with filename as String?

Sub TransferData()


    Dim strPath2 As String
    Dim wbkWorkbook1 As Workbook
    Dim wbkWorkbook2 As Workbook

    strPath2 = Dir("C:\*Hello*.xlsx")

    Set wbkWorkbook1 = ThisWorkbook 
    Set wbkWorkbook2 = Workbooks.Open(strPath2)

    wbkWorkbook2.Worksheets("Sheet1").Range("A1:J20").Copy
    wbkWorkbook1.Worksheets("Sheet1").Range("A1").PasteSpecial xlPasteValues


End Sub

1 Answer 1

4

It's very simple. I figured it out myself.

strPath2 = "C:\" & Dir("C:\*Hello*.xlsx")
Sign up to request clarification or add additional context in comments.

Comments

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.