set function and variable file names

Ox1138

New Member
Joined
Feb 18, 2019
Messages
2
Hi All

Thanks for any help on this, I am fairly new and still learning.

I am trying to develop a macro that will open, copy, (and if possible close) from about 50 closed workbooks. I am currently using this code:

Dim wb As Workbook
Set wb = Workbooks.Open("C:\Users\Me\Path\AA.csv", True, True)
ThisWorkbook.Activate

But this only opens the file AA.csv, I have a variable "Live" which cycles through the names of the closed workbooks. However, everytime I try to change the Set wb to something that has a variable in it, I seem to fail.

For clarity - I want to be able to change "aa.csv" (or any longer part of the string if necessary) within the macro.

Thanks for any help you can offer.

Cheers
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
For example:

Code:
Sub OpenWb()
    Dim wb As Workbook
    Dim live As Variant, wPath As String
    
    wPath = "C:\Users\Me\Path\"
    live = Dir(wPath & "*.csv")
    Do While live <> ""
        Set wb = Workbooks.Open(wPath & live, True, True)
        ThisWorkbook.Activate
        '
        'here your code
        '
        live = Dir()
    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top