Hello. I'm brand new to messing around with VBA, so please bear with me. I would like to know how to retrieve data from a user-selected Excel file of known formatting and reformat it in another file. The name of the imported file will change routinely, but the format is known and set.
From what I've gleaned online, I cannot do this without opening the other file, but perhaps I'm misunderstanding. Regardless, even with the other file opened, I'm having no luck.
Here's what I'd like to do:
1. Start Excel by opening the file to which I wish to transfer data (i.e. Import.xlsm)
2. Have a dialog window pop up for the user to navigate to the Excel file from which to get the data (i.e. Export 05-19-2012.xls). I've done this and have the entire path and file name as a String.
3. Automatically retrieve certain data from Export 05-19-2012.xls for use in Import.xlsm. For instance, Export has columns B & C with names and numbers that I wish to do some sorting and reformatting of, then copy into Import's columns A & B.
I've tried to copy just one cell to see if I'm on the right track, but even that hasn't worked. After defining Import's path as NewFile, I tried Range("A1") = Workbooks(NewFile).Sheets(1).Range("C12"). This produces an error. In fact, the only non-error inducing code I can make is Range("A1") = NewFile...but this just puts the file path into A1.
How do I access data inside the Export 05-19-2012 file from within Import's VBA code?
I hope this is all clear, but suspect it's not. Feel free to ask questions for clarification.
From what I've gleaned online, I cannot do this without opening the other file, but perhaps I'm misunderstanding. Regardless, even with the other file opened, I'm having no luck.
Here's what I'd like to do:
1. Start Excel by opening the file to which I wish to transfer data (i.e. Import.xlsm)
2. Have a dialog window pop up for the user to navigate to the Excel file from which to get the data (i.e. Export 05-19-2012.xls). I've done this and have the entire path and file name as a String.
3. Automatically retrieve certain data from Export 05-19-2012.xls for use in Import.xlsm. For instance, Export has columns B & C with names and numbers that I wish to do some sorting and reformatting of, then copy into Import's columns A & B.
I've tried to copy just one cell to see if I'm on the right track, but even that hasn't worked. After defining Import's path as NewFile, I tried Range("A1") = Workbooks(NewFile).Sheets(1).Range("C12"). This produces an error. In fact, the only non-error inducing code I can make is Range("A1") = NewFile...but this just puts the file path into A1.
How do I access data inside the Export 05-19-2012 file from within Import's VBA code?
I hope this is all clear, but suspect it's not. Feel free to ask questions for clarification.