Dynamic List for File Save Array

chipsworld

Board Regular
Joined
May 23, 2019
Messages
172
Office Version
  1. 365
Happy New year! Had a quick question.

How can I accomplish the below but from a dynamic list instead of putting the names in the code?

VBA Code:
arrWBS = Array("JESSICA", "FLEET", "****", "ALAN", "MASTER")
 
For i = LBound(arrWBS) To UBound(arrWBS)
       ThisWorkbook.SaveAs Filename:=pth & "BUY REPORT Ver" & Format(Now(), "yymm") & " v2.4 - " & arrWBS(i) & ".xlsm"

Next i
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Where exactly will this list be located?
 
Upvote 0
Happy New year! Had a quick question.

Happy New Year - here is a quick answer

Put the names in a Table (Listobject) & read the databodyrange in to an array

Untested but something like this

VBA Code:
    Dim tbl         As ListObject
    Dim FileName    As Variant, FileNames
  
    Set tbl = Worksheets("Sheet1").ListObjects(1)
    FileNames = tbl.DataBodyRange.Value2
  
    For Each FileName In FileNames
        ThisWorkbook.SaveAs FileName:=pth & "BUY REPORT Ver" & Format(Now(), "yymm") & " v2.4 - " & FileName & ".xlsm"
    Next FileName

Hope helpful

Dave

02-01-2025.xls
A
1File Name
2JESSICA
3FLEET
4ALAN
5MASTER
Sheet1
 
Upvote 0
Happy New Year - here is a quick answer

Put the names in a Table (Listobject) & read the databodyrange in to an array

Untested but something like this

VBA Code:
    Dim tbl         As ListObject
    Dim FileName    As Variant, FileNames
 
    Set tbl = Worksheets("Sheet1").ListObjects(1)
    FileNames = tbl.DataBodyRange.Value2
 
    For Each FileName In FileNames
        ThisWorkbook.SaveAs FileName:=pth & "BUY REPORT Ver" & Format(Now(), "yymm") & " v2.4 - " & FileName & ".xlsm"
    Next FileName

Hope helpful

Dave

02-01-2025.xls
A
1File Name
2JESSICA
3FLEET
4ALAN
5MASTER
Sheet1
Dave,
Had a glitch...

Run-TIme error 13 "Type Mismatch" on line - " ThisWorkbook.SaveAs FileName:=pth & "BUY REPORT Ver" & Format(Now(), "yymm") & " v2.4 - " & FileName & ".xlsm""
 
Upvote 0
Dave,
Had a glitch...

Run-TIme error 13 "Type Mismatch" on line - " ThisWorkbook.SaveAs FileName:=pth & "BUY REPORT Ver" & Format(Now(), "yymm") & " v2.4 - " & FileName & ".xlsm""
Skip the glitch! Thank you for the "Quick Answer"!

Have a great week!
 
Upvote 0
Skip the glitch! Thank you for the "Quick Answer"!

Have a great week!

Appreciate your feedback & glad we were able to help

In my haste in posting I overlooked that you had not specified the FileFormat

Rich (BB code):
ThisWorkbook.SaveAs FileName:=pth & "BUY REPORT Ver" & Format(Now(), "yymm") & " v2.4 - " & FileName & ".xlsm", FileFormat:=52

Excel 2007 > when using SaveAs method always best to provide both the FileFormat parameter and correct File extension

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,226,114
Messages
6,189,052
Members
453,522
Latest member
Seeker2025

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