VBA Code to Copy Entire Workbook

zach9208

Board Regular
Joined
Dec 15, 2015
Messages
117
I am looking for a code to copy an entire workbook and name it based on the cell value that is placed in A1.

I would also like A1 to change. I have a column that has all the values I would like to cycle through cell A1 until the column hits a blank cell.

After the cell changes if it would create the entire workbook that would be even better.

Any ideas?

Thanks in advance!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Not sure the question is explicit enough...
If I am getting this right... you want a macro that open an existing file and save it (filename based on the original file's A1) and do a loop until the last cell with data on Column A?
 
Upvote 0
This works for me:

Code:
Sub NameMe()

Dim nLastRow As Integer
Dim i As Integer
Dim wsName As String


nLastRow = Range("A" & Rows.Count).End(Direction:=xlUp).Row

For i = 1 To nLastRow
    
    wsName = Cells(i, 1).Value
    ActiveWorkbook.SaveAs Filename:=wsName, FileFormat:=52
  
  
Next i

End Sub
 
Upvote 0
Hi Jeff!

I have a total of 6 tabs. Each tab feeds off the value in A1, as I have sumifs slicing and dicing data that is stored on a data tab. I need cell A1 on the first worksheet to cycle down a client list that is stored in column A on another tab, say the second tab. In column A there is a list of values that I need to feed into A1 first, then duplicate the workbook and save the file with the title of the current value in A1.

I need this ofcourse to loop through all the available values in column A on the second tab and create a seperate workbook for each client with all tabs.

Hope this makes more sense. Thanks!!!
 
Upvote 0
I am going to make this even more exact.

The cell I need to change is cell B5 on the tab labeled "Summary". The list of all values I need to enter into cell B5 is stored on a tab called "Drop Down List Data" in column A. I do have column headers so I need the list to cycle down from cell A2.

I need cell B5 on the summary tab to change to the first available cell down this list, then duplicate the entire workbook after this changes. I need this to loop saving duplicate workbooks until I hit an empty cell in column A of the "drop down list" tab. I would like each workbook to inheret the name of cell B5 of the summary tab with each duplicated workbook.

I know this is complex, so I appreciate the help.
 
Upvote 0
This is the closest code that I have found. Any ideas on how to modify this to loop and save the file as the the current value in B5 of the summary tab. See comment above.

Code:
Private Sub SaveWorkbookAsNewFile(NewFileName As String)
    Dim ActSheet As Worksheet
    Dim ActBook As Workbook
    Dim CurrentFile As String
    Dim NewFileType As String
    Dim NewFile As String
 
    Application.ScreenUpdating = False    ' Prevents screen refreshing.
 
    CurrentFile = ThisWorkbook.FullName
 
    NewFileType = "Excel Files 1997-2003 (*.xls), *.xls," & _
               "Excel Files 2007 (*.xlsx), *.xlsx," & _
               "All files (*.*), *.*"
 
    NewFile = Application.GetSaveAsFilename( _
        InitialFileName:=NewFileName, _
        fileFilter:=NewFileType)
 
    If NewFile <> "" And NewFile <> "False" Then
        ActiveWorkbook.SaveAs Filename:= NewFile, _
            FileFormat:=xlNormal, _
            Password:="", _
            WriteResPassword:="", _
            ReadOnlyRecommended:=False, _
            CreateBackup:=False
 
        Set ActBook = ActiveWorkbook
        Workbooks.Open CurrentFile
        ActBook.Close
    End If
 
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

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