Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Save as variable file name

Hi there,
I've got a list of 55 cities, and I'd like a macro to go down the list one
by one, and save the file with each city as the file name, so that in the end
I have 55 different files, each called city1.xls and city 2.xls and so forth.
I'm sure this is possible but not sure where to start!
Thanks for your help...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Save as variable file name

Try the below...Edit the workbooknames ..Assume the workbook is open

Sub Macro()
Dim cell As Range, wb As Workbook
Set wb = Workbooks("Whichworkbook.xls")

Application.DisplayAlerts = False
'Specify the range in which the cities are mentioned...
For Each cell In Workbooks("book3.xls").Sheets("Sheet3").Range("A5: A8")
If cell.Text < "" Then
wb.SaveAs "d:\" & cell.Text & ".xls", xlNormal
End If
Next
Application.DisplayAlerts = True
End Sub


--
Jacob (MVP - Excel)


"Plum" wrote:

Hi there,
I've got a list of 55 cities, and I'd like a macro to go down the list one
by one, and save the file with each city as the file name, so that in the end
I have 55 different files, each called city1.xls and city 2.xls and so forth.
I'm sure this is possible but not sure where to start!
Thanks for your help...

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Save as variable file name

Assumes file names are in Column "A".

Sub SaveAsX()
Dim rCell As Range
Dim strPath As String

For Each rCell In Range("A1:A54")
ThisWorkbook.SaveAs _
"YOUR PATH HERE/" & rCell
Next rCell
End Sub



--
Regards
Dave Hawley
www.ozgrid.com


"Plum" wrote in message
...
Hi there,
I've got a list of 55 cities, and I'd like a macro to go down the list one
by one, and save the file with each city as the file name, so that in the
end
I have 55 different files, each called city1.xls and city 2.xls and so
forth.
I'm sure this is possible but not sure where to start!
Thanks for your help...


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Save as variable file name

thank you both that is fabulous!

"ozgrid.com" wrote:

Assumes file names are in Column "A".

Sub SaveAsX()
Dim rCell As Range
Dim strPath As String

For Each rCell In Range("A1:A54")
ThisWorkbook.SaveAs _
"YOUR PATH HERE/" & rCell
Next rCell
End Sub



--
Regards
Dave Hawley
www.ozgrid.com


"Plum" wrote in message
...
Hi there,
I've got a list of 55 cities, and I'd like a macro to go down the list one
by one, and save the file with each city as the file name, so that in the
end
I have 55 different files, each called city1.xls and city 2.xls and so
forth.
I'm sure this is possible but not sure where to start!
Thanks for your help...


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Save As Variable File Name [email protected] Excel Programming 10 May 25th 05 12:27 PM
Save to Path & Variable file name Otto Moehrbach[_6_] Excel Programming 4 September 2nd 04 10:44 PM
Save File to Another Directory, but not change Users File Save location Mike Knight Excel Programming 1 May 28th 04 09:06 PM
Using a variable string in a file save path Ron[_13_] Excel Programming 1 October 16th 03 08:29 PM


All times are GMT +1. The time now is 07:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"