Solved

Save Excel as individual workbook

Posted on 2016-08-23
6
31 Views
Last Modified: 2016-09-14
Hello EE,

Can someone please help me with excel macro to save excel tabs as individual workbooks?  My large excel file has formulas and charts.  I will like a macro to copy and paste values prior to saving as individual workbooks into the same path.

Thanks in advance for your help.
0
Comment
Question by:fb1990
  • 4
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
xtermie earned 500 total points (awarded by participants)
ID: 41766539
Sub CreateWorkbooks()
'Creates an individual workbook for each worksheet in the active workbook.
Dim wbDest As Workbook
Dim wbSource As Workbook
Dim sht As Object 'Could be chart, worksheet, Excel 4.0 macro,etc.
Dim strSavePath As String

On Error GoTo ErrorHandler

Application.ScreenUpdating = False 'Don't show any screen movement

strSavePath = "C:\Temp\" 'Change this to suit your needs

Set wbSource = ActiveWorkbook

For Each sht In wbSource.Sheets
 sht.Copy
 Set wbDest = ActiveWorkbook
 wbDest.SaveAs strSavePath & sht.Name
 wbDest.Close 'Remove this if you don't want each book closed after saving.
Next

Application.ScreenUpdating = True

Exit Sub

ErrorHandler: 'Just in case something hideous happens
MsgBox "An error has occurred. Error number=" & Err.Number & ". Error description=" & Err.Description & "."
End Sub

Open in new window

0
 
LVL 17

Assisted Solution

by:xtermie
xtermie earned 500 total points (awarded by participants)
ID: 41766544
Macro to copy and paste values in each worksheet in a workbook is provided here:
https://www.experts-exchange.com/questions/27808846/Macro-to-copy-paste-special-values-all-sheets-in-workbook.html

I think you should use the code proposed by Elton Pascua but comment out a few lines
Sub test()
    
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim rngFormulas As Range
    
    Set wb = ThisWorkbook

    Application.ScreenUpdating = False
        
    'For Each ws In wb.Worksheets
    '     ws.Unprotect "xxxx"
    '    ws.Calculate
    'Next ws
        
    Application.Calculation = xlCalculationManual
        
    For Each ws In wb.Worksheets
        On Error Resume Next
        ws.Cells.Copy
        ws.Cells.PasteSpecial xlPasteValues
    Next ws
        
    'wb.Worksheets("Data").Delete
    'wb.Worksheets("Mapping").Delete
    'wb.Worksheets.Copy
        
End Sub

Open in new window

Use that prior to running the macro above

Hope this helps!
0
 
LVL 1

Author Comment

by:fb1990
ID: 41766773
xtermie, thanks for the solution.  Is there a way to just save the spreadsheet out after the paste value and not take away my formulas from the master file?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 17

Assisted Solution

by:xtermie
xtermie earned 500 total points (awarded by participants)
ID: 41766845
The formula should not be taken away...hmm...yes, we are using a SAVEAS for each of the worksheets in the first macro...but in the second one there is no save...try this for copying-pasting the values and saving the initial file as something with values only:

Sub copypastevalues()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim rngFormulas As Range
    Dim strSavePath As String
    
    Set wb = ThisWorkbook
    strSavePath = "C:\Test\"
    strFileName = "ValuesOnly.xlsx"
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
        
    For Each ws In wb.Worksheets
        On Error Resume Next
        ws.Cells.Copy
        ws.Cells.PasteSpecial xlPasteValues
    Next ws
            
    wb.SaveAs strSavePath & strFileName
        
End Sub

Open in new window

0
 
LVL 17

Expert Comment

by:xtermie
ID: 41793905
Good comment and suggestions provided but not feedback on final outcome or awarding of point from the author
0
 
LVL 1

Author Comment

by:fb1990
ID: 41798471
Hello xtermie,

Please accept my apology.  I have been out of pocket for a while now.  I needed to award the point and close the request.  I can't seem to find where to do that
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to Auto-fill data in Database 2 19
Excel filter by strike though 8 25
TT Status Chang 3 30
Name Rotation 11 27
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now