Create new workbook from selected worksheets of master file (values only)

berlinhammer

Board Regular
Joined
Jan 30, 2009
Messages
187
Hello,

I have a very large workbook containing a lot of worksheets with a lot of data, formulae, data connections and macros. I like having the master file as a central source but I need to send it to various Global locations for verification, and the size and complexity of the file is a problem.

On a high level I think what would really be beneficial would be a macro which exports a group of selected worksheets to a new workbook, as values only and with any links/formulae/macros broken.

My googling leads to believe that this is more compliacted to achieve than I would have liked. Is this fair to say? My VBA is decent though far from expert, and I have never written anything involving grouped sheets or file creation before.

Has anyone come across a similar macro to the purpose I am describing or have a suggestion as to a good place to start? Such as the syntax for copying and exporting a group of sheets.

Grateful for any help or advice anyone can offer,

Thank you

Jon
 
Vladimir, i noticed in your code the code copies to new workbook, i would prefer the code to not copy to new workbook but rather use this workbook as a template because once the user Saveas the template would not have been effected with the below actions.

Try this code:
Rich (BB code):

Sub CopyShtsAsValues()
  
  Dim Sh As Worksheet
  
  On Error GoTo exit_
  
  ' Screen off
  Application.ScreenUpdating = False
  
  ' Copy sheets into new workbook
  Sheets.Copy
  
  ' Replace formulas by values
  For Each Sh In Worksheets
    Sh.Visible = xlSheetVisible
    With Sh.UsedRange
      .Copy
      .PasteSpecial xlPasteValues
    End With
  Next
  
  ' Make some sheets very hidden
  Sheets("RawData").Visible = xlSheetVeryHidden
  Sheets("FX").Visible = xlSheetVeryHidden
  
  ' Disable copy mode, restore screen on
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
  
  ' Call SaveAs dialog
  ChDrive ThisWorkbook.Path
  ChDir ThisWorkbook.Path
  CommandBars.FindControl(, 748).Execute
  
exit_:
  
  ' Trap error
  If Err Then MsgBox Err.Description, vbCritical, "Error"
  
End Sub
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Isabella, just comment this line: Sheets.Copy
Please take into account that the thread is named as Create NEW workbook from SELECTED worksheets, but your task is now different to the original.
Regards
 
Upvote 0
Isabella, just comment this line: Sheets.Copy
Please take into account that the thread is named as Create NEW workbook from SELECTED worksheets, but your task is now different to the original.
Regards

Thanks Vladimir. I did not create this thread, i thought it was similar to my task so i continued with the thread.
 
Upvote 0
Isabella, it’s ok, but it was the reason for me to think about new workbook.
BTW replacing of formulas by values in active workbook is not safety in case of user choose Cancel and will save workbook later with the same name (without formulas).
But there is no issue if you really use XLT template file not just XLS workbook as template.
 
Last edited:
Upvote 0
Isabella, it’s ok, but it was the reason for me to think about new workbook.
BTW replacing of formulas by values in active workbook is not safety in case of user choose Cancel and will save workbook later with the same name (without formulas).
But there is no issue if you really use XLT template file not just XLS workbook as template.

Vladimir, i was thinking the same thing, the file is XLS workbook. What do you propose as an alternative if the user cancel then Exit Sub?
 
Upvote 0
Vladimir, i was thinking the same thing, the file is XLS workbook. What do you propose as an alternative if the user cancel then Exit Sub?
For me the using of new workbook is more safe
 
Upvote 0
For me the using of new workbook is more safe

Vladimir, i have taken your suggestion of copying to a new wkbk by uncommenting the Sheets.Copy, when i save the wkbk and re-open all the worksheets are selected, i had to go to each worksheet and select a cell, can this be adopted in code?
 
Upvote 0
Vladimir, i have taken your suggestion of copying to a new wkbk by uncommenting the Sheets.Copy, when i save the wkbk and re-open all the worksheets are selected, i had to go to each worksheet and select a cell, can this be adopted in code?
Isabella,

There is nothing in the code to select all sheets.
Copying of already selected sheets was used only in post #2 for Jon’s task.

If sheets been selected before running of code, then for deselecting it, add the following code below the line Sheets.Copy:
Sheets(1).Select

Regards
 
Upvote 0
Isabella,

There is nothing in the code to select all sheets.
Copying of already selected sheets was used only in post #2 for Jon’s task.

If sheets been selected before running of code, then for deselecting it, add the following code below the line Sheets.Copy:
Sheets(1).Select

Regards

Vladimir, is it possible to save and close the master workbook via code to avoid any confusion with the the new wkbk?
 
Upvote 0
Vladimir, is it possible to save and close the master workbook via code to avoid any confusion with the the new wkbk?
Sure, Isabella.

1. Saving: ThisWorkbook.Save

2. Closing: ThisWorkbook.Close
If there are not saved changes in closing workbook, then Excel prompts for saving changes.

Regards
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,107
Members
449,205
Latest member
ralemanygarcia

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