Page 1 of 1

1337 Excel [Help using VBA]

Posted: 29 Mar 2012, 12:48
by StarPhoenix
G'day

I have been asked to break up an Excel workbook containing a number of worksheets such that each worksheet is transferred to its own workbook.

Now I could do this the usual junior admin. assistant way, create a slew of .xls files, right-click on each worksheet tab of the original workbook, and choose "Move", but I am lazy.

I found the following super advanced method, but don't know the first thing about Visual Basic for Applications.

How would I use the following:

Code: Select all

Sub splittest()
    Dim sht As Worksheet
    Dim w As Worksheet
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each sht In Worksheets
        Set neww = Workbooks.Add
        sht.Copy neww.Worksheets(1)
        With neww
            For Each w In Worksheets
                If w.Name <> sht.Name Then
                    w.Delete
                End If
            Next w
        End With
        neww.SaveAs sht.Parent.Path & "\" & sht.Name
        neww.Close
    Next sht
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub
:run4hills: from the VBHaters

Thank you

Re: 1337 Excel [Help using VBA]

Posted: 29 Mar 2012, 18:47
by RuadRauFlessa
If you want to be 1337 do it the way you know how... you will get better results by actually just sitting and droning through it than wasting hours trying to make that script work for your situation.

Re: 1337 Excel [Help using VBA]

Posted: 29 Mar 2012, 18:53
by Tribble
I am no expert and am thinking in C# and XAML at the moment so not sure if this will help:

Code: Select all

Sub test()
ActiveWorkbook.ActiveSheet.Move
End Sub

Re: 1337 Excel [Help using VBA]

Posted: 29 Mar 2012, 21:25
by StarPhoenix
Thank you :-)

Re: 1337 Excel [Help using VBA]

Posted: 29 Mar 2012, 21:27
by Tribble
Pleasure - you know how to run it hey?