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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,829
Messages
6,121,826
Members
449,051
Latest member
excelquestion515

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