Link to home
Start Free TrialLog in
Avatar of fb1990
fb1990

asked on

Running Multiple Macros in Excel Simultaneously

Hello EE,

I have 3 sets of macros in my excel workbook.  I created a fourth macro to run the other 3 macros, but i am getting

Compile Error:  
                      Expected variable or procedure, not module

Can someone please help me?

Thanks.
Avatar of Steve
Steve
Flag of United States of America image

Might be a mis-spelled macro name..

Public Sub RunEm()
macroname1
macroname2
macroname3
End Sub

Open in new window

Avatar of Joe Howard
Can't help without seeing the macros.
Avatar of fb1990
fb1990

ASKER

Her are the macros

Code1

Sub CreateTree()

    Set DestSht = Sheets.Add(After:=Sheets(Sheets.Count))
    DestSht.Name = "Tree"
    Sheets("Data10").Columns("O:O").Copy Destination:=DestSht.Range("D1")
    Sheets("Data10").Columns("C:C").Copy Destination:=DestSht.Range("E1")
    Sheets("Data10").Columns("J:J").Copy Destination:=DestSht.Range("G1")

    Application.CutCopyMode = False
    
End Sub

Open in new window


Code2

Sub Createnew()
    Sheets("Data10").Range("J1").AutoFilter
    Set DestSht = Sheets.Add(After:=Sheets(Sheets.Count))
    DestSht.Name = "Winners"
    Sheets("Data10").Columns("A:A").Copy Destination:=DestSht.Range("A1")
    Sheets("Data10").Columns("B:B").Copy Destination:=DestSht.Range("B1")
    Sheets("Data10").Columns("D:D").Copy Destination:=DestSht.Range("C1")
    Sheets("Data10").Columns("E:E").Copy Destination:=DestSht.Range("D1")
    Sheets("Data10").Columns("G:G").Copy Destination:=DestSht.Range("E1")
    Sheets("Data10").Columns("J:J").Copy Destination:=DestSht.Range("F1")
    Sheets("Data10").Columns("K:K").Copy Destination:=DestSht.Range("G1")
    Sheets("Data10").Columns("P:P").Copy Destination:=DestSht.Range("H1")

    Application.CutCopyMode = False
    Sheets("Data10").Range("J1").AutoFilter
End Sub

Open in new window


Code 3

Sub SaveWorksheetsAsCsv()

Dim ws As Worksheet, wb As Workbook

    For Each ws In ThisWorkbook.Worksheets
        ws.Copy 'creates a new workbook
        With ActiveWorkbook
            .SaveAs "C:\Users\xxx\" & ws.Name & ".csv", xlCSV
            .Close False
        End With
    Next ws

End Sub

Open in new window

There are no compile (or runtime) errors in the code you provided, the error must be somewhere else, Which line gets selected when you encounter the error?
Avatar of fb1990

ASKER

I get the error when i run this code that was placed in another module

Sub AllCombined()

 Call CreateTree
 Call Createnew
 Call SaveWorksheetsAsCsv
 
End Sub
 User generated image
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, if you gave the module the same name as the procedure, you would get the error message you originally mentioned. It's generally considered bad practice to do that, so rename the module and then the Call code should work.
Avatar of fb1990

ASKER

Thanks to everyone that contributed.  For some reason the solution did not work for me, but i got some idea from the assistance that was provided.  Here is the solution that worked for me

Sub Master()

Application.Run "'C:My DocumentsFilename.xlsm'!CreateTree.CreateTree"
Application.Run "'C:My DocumentsFilename.xlsm'!CreateNew.CreateNew"
Application.Run "'C:My DocumentsFilename.xlsm'!SaveAsCSV2.SaveCSV2"

End Sub