Solved

create a new file for ever tab in workbook and save file with name in cell 'B2'

Posted on 2014-02-20
7
200 Views
Last Modified: 2014-02-20
I need to create a new file for ever tab in workbook and save file with name in cell 'B2'

Would an expert be able to provide the code for doing this

Path is Z:\Flex Rate\Macro

Thanks
0
Comment
Question by:Jagwarman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39872825
Hi,

pls try

Sub SplitWorkbook()
    Dim sht As Worksheet
    For Each sht In ThisWorkbook.Sheets
            sht.Copy
            ActiveWorkbook.SaveAs Filename:="Z:\Flex Rate\Macro\" & sht.Range("B2") & ".xlsx"
            ActiveWorkbook.Close SaveChanges:=False
    Next sht
End Sub

Open in new window

Regards
0
 

Author Comment

by:Jagwarman
ID: 39872845
Hi Rgonzo1971

I get Method SaveAs of object_ workbook failed
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39872861
Hi,

What comes in the MsgBox?
Sub SplitWorkbook()
    Dim sht As Worksheet
    For Each sht In ThisWorkbook.Sheets
            sht.Copy
            MsgBox "Filename: " & sht.Range("B2") 
            ActiveWorkbook.SaveAs Filename:="Z:\Flex Rate\Macro\" & sht.Range("B2")
            ActiveWorkbook.Close SaveChanges:=False
    Next sht
End Sub

Open in new window

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Jagwarman
ID: 39872922
First time round it saves the shet named Data Sheet and gives me name of next sheet. Next time MsgBox is blank and then it falls over
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39872978
From your description not all sheets have a filename at Range("B2")

Is that right?
0
 

Author Comment

by:Jagwarman
ID: 39872983
Ah what an Idiot I am. Brilliant Rgonzo it works perfectly. Thanks
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 39875712
Is your problem solved, Jagwarman? If so, you'll want to accept a comment as the solution, no? :)
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

623 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