vba routine to save

Colleen45

Active Member
Joined
Jul 22, 2007
Messages
495
I have a workbook (Library Stock Register Ver 4.0) that I need to save as 103 different names
I also have the list of names in a separate workbook (called names)which start in column a1
is there a way we could get VBA to do this laborious task
ie take the first name from "Names" list insert it into the save as dialogue of (Library Stock Register Ver 4.0 workbook), close it go to the next name on the list and do the same thing

Thanks
Colleen
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Do you need to open, modify and/or save the stock file, or could we just create copies and rename them?
 
Upvote 0
Something like this should work. It assumes that both workbooks are open, the names include the file extension, and you may need to change the bits in red to suit

Rich (BB code):
Sub test()
Dim i As Long
With Workbooks("Library Stock Register Ver 4.0.xlsx")
    For i = 1 To 103
        .SaveCopyAs Filename:=.Path & "\" & Workbooks("Names.xlsx").Sheets("Sheet1").Range("A" & i)
    Next i
End With
End Sub
 
Upvote 0
Code:
Do you need to open, modify and/or save the stock file, or could we just create copies and rename them? 
[code]

No the same file just needs to be saved under  103 names,  and yes there is extensive vba code inside the file
 
Upvote 0
Something like this should work. It assumes that both workbooks are open, the names include the file extension, and you may need to change the bits in red to suit


Code:
Sub test()
Dim i As Long
With Workbooks("Library Stock Register Ver 4.0.xlsx")
For i = 1 To 103
.SaveCopyAs Filename:=.Path & "\" & Workbooks("Names.xlsx").Sheets("Sheet1").Range("A" & i)
Next i
End With
End Sub


Thanks Peter, can i run this from the work book that has the list of names rather, the stock work book has been protected, and i think it may involve more complex issues if we have to unprotect and then protect again just to run the code, my thinking is that it would be simpler to just to take that stock file and rename, yes both files can be open, but the stock one should remain protected
 
Upvote 0
Put the code in the names.xls and make sure it's in the same folder as the sheet you need to duplicate/rename

Code:
Sub dupeFile()
    fldr = ActiveWorkbook.Path
    fname = "Library Stock Register Ver 4.0.xls"
    With ActiveSheet
        For Each c In .Range("A1", .Cells(Rows.Count, 1).End(xlUp))
            FileCopy fldr & "\" & fname, fldr & "\" & c.Value & ".xls"
        Next
    End With
End Sub
Change names to suit. This has the advantage of not requiring the stock register sheet to be opened at all.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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