• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

many workbooks to be created and save

Shanmugam N

New Member
Hi i need a macro coding for the below question i tried something but its not working could you pls help..?

Create a macro which will ask the user how many workbooks to be created and save that many workbooks. The title can be saved as 1.xlsx , 2.xlsx and so on

I tried like this
Sub Scenario15()
Dim i As Double
For i = 1 To Workbooks.Count
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\Shan" & i & ".xlsx"
ActiveWorkbook.Close
Next
End Sub
 
Hey Shanmugam

please refer below code -

Have added two input box to get user information


Code:
Sub Scenario15()
Dim i As Double
Dim UserIputCnt As Integer
Dim UserIputFolder As String


UserIputCnt = VBA.InputBox("Please enter the number of workbooks you want")
UserIputFolder = VBA.InputBox("Please enter the folder name")

On Error Resume Next
CurPath = Application.ActiveWorkbook.Path

UserIputFolder = CurPath & "\" & UserIputFolder

' Make folder dir.
       
        MkDir UserIputFolder
       
        If Err.Number <> 0 Then
        rn = Int(Int(10000 - 6) * Rnd)
        UserIputFolder = UserIputFolder & rn
       
        MkDir UserIputFolder
        End If



For i = 1 To UserIputCnt
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=UserIputFolder & "\" & i & ".xlsx"
ActiveWorkbook.Close
Next

Call Shell("explorer.exe" & " " & UserIputFolder, vbNormalFocus)


End Sub


Hi i need a macro coding for the below question i tried something but its not working could you pls help..?

Create a macro which will ask the user how many workbooks to be created and save that many workbooks. The title can be saved as 1.xlsx , 2.xlsx and so on

I tried like this
Sub Scenario15()
Dim i As Double
For i = 1 To Workbooks.Count
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\Shan" & i & ".xlsx"
ActiveWorkbook.Close
Next
End Sub
 
Back
Top