Variable file name and path with button

  • Hello! I have this code:

    Set w1 = Workbooks("1.xlsx").Sheets("Sheet1")

    Set w2 = Workbooks("2.xlsx").Sheets("Sheet1")

    My poblem is, every time the 2.xlsx file name change, and i would like change it each time, possible to do with button, just browse the file? Its something simple code just copy few cells after if its match with the 1.xlsx file. Th 1.xlsx file can be fix because for this file never change the name, but the 2.xlsx filename always can be anything. I dont have too much experience with VBA, and its totally different than C# so i stuck here.

    Somebody can help me please, how possible give for w2 file name and path with button? Thank you!

  • Here's a bit of example code for opening a workbook and then doing stuff with it:

    And just in case, really simple guide on adding a button:

  • Thank you very much your help. I did something like this, but sadly its not work i get always error:

  • You're trying to access cells of a workbook. Workbooks don't have cells, only worksheets/range objects do

    Slight tweak:

  • Put this under your variable declarations (The "Dim" statements):

    set Dic = CreateObject("Scripting.Dictionary")

    And then, just above "End Sub" type this:

    set Dic = Nothing

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!