Macro Help

Kyosti

Board Regular
Joined
Jun 2, 2008
Messages
90
The following macro is designed to split several tabs within a sheet into individual files. What I would like to do is get this part of the macro: Format(Date, " BOB mm-yyyy" to prompt a dialog box once at the beginning of the macro to ask what is the additional name tag the files should use. This part of the file name is the same across every file it is only the first part of the file name that is unique. Can anyone help me?


Sub Filesplit()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "Data" Then
sh.Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "" & sh.Name & Format(Date, " BOB mm-yyyy") & ".xlsx", FileFormat:=51
ActiveWorkbook.Close False
End If
Next
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Untested - may need some tweaking for path separator and spacing within the file name.
Code:
Sub Filesplit()
Dim sh As Worksheet, fName As String
fName = InputBox("Enter file name prefix")
If fName = "" Then Exit Sub
fName = " " & fName & " " & Format(Date, "mm-yyyy")
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "Data" Then
sh.Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & sh.Name & fName & ".xlsx", FileFormat:=51
ActiveWorkbook.Close False
End If
Next
End Sub
 
Upvote 0
Code:
Sub Filesplit()
    Dim sh As Worksheet, Nm As String
    Nm = InputBox("Please enter the name prefix...", "Name required")
    For Each sh In ThisWorkbook.Sheets
        If sh.Name <> "Data" Then
            sh.Copy
            ActiveWorkbook.SaveAs ThisWorkbook.Path & "" & sh.Name & " " & Nm & Format(Date, " mm-yyyy") & ".xlsx", FileFormat:=51
            ActiveWorkbook.Close False
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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