Creating new workbook

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,220
Office Version
  1. 2013
Platform
  1. Windows
Good Day,
Is it possible to create new workbook which contains sheet1 datas only from master workbook by clicking command button,and the name of workbook will be asking by inputbox and create accordingly??
Many Thanks.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Good Day,
Is it possible to create new workbook which contains sheet1 datas only from master workbook by clicking command button,and the name of workbook will be asking by inputbox and create accordingly??
Many Thanks.


Do you mean something like this?

Sub NewWorkbook()
'
'
Application.DisplayAlerts = False
Dim i As Integer
Dim FileName1 As String
For i = 2 To (how ever many sheets are in the Master)
Worksheets("Sheet" & i).Select
ActiveWindow.SelectedSheets.Delete
Next i
FileName1 = InputBox("Enter New Workbook Name")
ActiveWorkbook.SaveAs Filename:="D:\" & FileName1, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True
End Sub
 
Upvote 0

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,220
Office Version
  1. 2013
Platform
  1. Windows
Thanks for your reply,but this code creats whole workbook .Actually nothing wrong with it but i need to get only sheet1 values as it is..
My master workbook has large of entries i don't need to create whole copy of workbook.Hope somone can help me on this problem.
Many Thanks
Code:
Sub Button1_Click()
Application.DisplayAlerts = False
Dim i As Integer
Dim FileName1 As String
For i = 2 To (1)
Worksheets("Sheet1" & i).Select
ActiveWindow.SelectedSheets.Delete
Next i
FileName1 = InputBox("Enter New Workbook Name")
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\me\Desktop\work" & FileName1, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True
End Sub
 
Upvote 0

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Thanks for your reply,but this code creats whole workbook .Actually nothing wrong with it but i need to get only sheet1 values as it is..
My master workbook has large of entries i don't need to create whole copy of workbook.Hope somone can help me on this problem.
Many Thanks
Code:
Sub Button1_Click()
Application.DisplayAlerts = False
Dim i As Integer
Dim FileName1 As String
For i = 2 To (1)
Worksheets("Sheet1" & i).Select
ActiveWindow.SelectedSheets.Delete
Next i
FileName1 = InputBox("Enter New Workbook Name")
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\me\Desktop\work" & FileName1, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True
End Sub

Your welcome. I thought the code was what you wanted. You asked "to create new workbook which contains sheet1 datas only". The For Loop as I sent it eliminates all sheets from the master except Sheet1. You made some changes too the For Loop (i.e. I gave For i = 2 To the number of sheets in the master - you changed to too For i = 2 To (1); Also, I gave Worksheets("Sheet" & i).Select - you changed too Worksheets("Sheet1" & i).


You asked "the name of workbook will be asking by inputbox and create accordingly?". The second part of the code creates a new workbook and prompts for a name.??

Altogether when you run the code you should have a new workbook, with sheet1 data only, and you fill in the name by prompt. If you wanted the master to remain on the screen, you could add an open command at the end of the code.

Anyway. That was my understanding of what you wanted. There's probably a better way, hope someone can help you.
 
Upvote 0

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,220
Office Version
  1. 2013
Platform
  1. Windows
Jonh have you tested the code you've posted ?? its not working unless have some changes.But still creating the new workbook with all datas including macros....
Thanks
Sub NewWorkbook()
'
'
Application.DisplayAlerts = False
Dim i As Integer
Dim FileName1 As String
For i = 2 To (how ever many sheets are in the Master)
Worksheets("Sheet" & i).Select
ActiveWindow.SelectedSheets.Delete
Next i
FileName1 = InputBox("Enter New Workbook Name")
ActiveWorkbook.SaveAs Filename:="D:\" & FileName1, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True
End Sub <!-- / message -->
 
Upvote 0

westconn1

Board Regular
Joined
Feb 20, 2009
Messages
245
Code:
x = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 1
Set newbook = Workbooks.Add
Application.SheetsInNewWorkbook = x
ActiveWorkbook.Sheets("sheet1").Copy (newbook.Sheets(1))
Application.DisplayAlerts = False
newbook.Sheets(2).Delete
Application.DisplayAlerts = True
Application.Dialogs(xlDialogSaveAs).Show

the user can dump the new workbook if he clicks cancel to the saveas
 
Upvote 0

westconn1

Board Regular
Joined
Feb 20, 2009
Messages
245
some reason, can't edit
corrected that the newworkbook becomes activeworkbook
Code:
n = ActiveWorkbook.Name
x = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 1
Set newbook = Workbooks.Add
Application.SheetsInNewWorkbook = x
Workbooks(n).Sheets("sheet1").Copy (newbook.Sheets(1))
Application.DisplayAlerts = False
newbook.Sheets(2).Delete
Application.DisplayAlerts = True
Application.Dialogs(xlDialogSaveAs).Show
 
Upvote 0

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,220
Office Version
  1. 2013
Platform
  1. Windows
Thanks WestConn,
After Saving the file how can we exit the new workbook?
 
Upvote 0

Forum statistics

Threads
1,191,054
Messages
5,984,388
Members
439,883
Latest member
onions44

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
Top