+ Reply to Thread
Results 1 to 6 of 6

To Call 2 macros

Hybrid View

napalm To Call 2 macros 11-13-2006, 06:23 PM
mudraker You will need to post your... 11-13-2006, 06:29 PM
napalm Right, sorry about that.... 11-13-2006, 06:39 PM
mudraker Code looks ok to me How... 11-13-2006, 10:14 PM
napalm orginally i just made a macro... 11-13-2006, 10:23 PM
napalm ahhh dont worry about me.... 11-14-2006, 03:09 AM
  1. #1
    Registered User
    Join Date
    11-13-2006
    Location
    Sydney Australia
    Posts
    4

    To Call 2 macros

    Hi all,
    i couldnt find anything relating to this in previous threads & was wondering if anyone could shed somelight on this.

    I have a macro that builds a TimeSheet. [named AutoWrecker]
    I have another macro that is a User Input form [named frmEmployeeDetails]

    When i run the form , you input a name & hours worked & it sends the data to
    the TimeSheet. Easy.

    but i now have to make a macro named 'startup' , that will call both of these macros.
    not knowing much about this, i just assumed it was:

    Sub Startup()
    Call AutoWreckers
    Call FrmEmployeeDetails.Show
    EndSub

    This obviously opens both the macros, but there in no longer communication between them. When data in inputted now, it is no longer sent to the timesheet.
    Is anyone able to clarify what i need to add ?.
    Thanks in advance

    napalm

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    You will need to post your code for the 2 macros so that we can see why it is failing

  3. #3
    Registered User
    Join Date
    11-13-2006
    Location
    Sydney Australia
    Posts
    4
    Right, sorry about that.
    napalm



    Autowreckers TimeSheet
    Sub AutoWreckers()
    '
    ' AutoWreckers Macro
    ' Macro to create Employee Time Sheet 
    '
    ' Keyboard Shortcut: Ctrl+x
    '
    ' This code selects A2:C2, merges cells, centres text , colours background & includes title
    
        Range("A2").FormulaR1C1 = "Down Town Auto Wreckers"
        Range("A3").FormulaR1C1 = "Employee's Time Sheet"
        
    ' Centre the headings
    
        Range("A2:C2").Select
        Selection.HorizontalAlignment = xlCenter
        Selection.Merge
        
        Range("A3:C3").Select
        Selection.HorizontalAlignment = xlCenter
        Selection.Merge
        
    ' Shaded headings
        
        Range("A2:C3").Interior.ColorIndex = 15
    
    ' Enter rate of pay
        
        Range("A5").FormulaR1C1 = "Rate Of Pay"
        Range("B5").FormulaR1C1 = "$10.50 "
    
    ' Enter Sub headings
    
        
        Range("A7").FormulaR1C1 = "Employee name"
        Range("B7").FormulaR1C1 = "Hours worker"
        Range("C7").FormulaR1C1 = "Pay"
        
    ' Widen Columns
    
        Columns("A:C").ColumnWidth = 15
    
    ' Right Alignment Pay Heading
        
        Range("C7").HorizontalAlignment = xlRight
    
    ' Place line
    
        Range("A7:C7").Borders(xlEdgeBottom).Weight = xlMedium
    
    ' Enter the formula for C8
            
        Range("C8").FormulaR1C1 = "=R5C2*RC[-1]"
        Range("C8").NumberFormat = "$#,##0.00"
        
    End Sub
    Code for Input Form
    Private Sub UserForm_Activate()
    'Initialise controls of the form
    
    txtEmployeeName.Text = ""
    txtHours.Text = spnHours.Value
    End Sub
    
    
    Private Sub spnHours_Change()
    
    'Reflect the value of spinner in text box
    
    txtHours.Text = spnHours.Value
    End Sub
    
    
    Private Sub CmdCancel_Click()
    'Hide form
    
    frmEmployeeDetails.Hide
    End Sub
    
    
    Private Sub cmdOK_Click()
    'Tranfer Data to the worksheet
    
    Sheets("Sheet1").Range("A8").Value = txtEmployeeName.Text
    Sheets("Sheet1").Range("B8").Value = txtHours.Value
    
    'Close The Form
    frmEmployeeDetails.Hide
    
    'Initialise form
    txtEmployeeName.Text = ""
    txtHours.Text = spnHours.Value
    End Sub

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Code looks ok to me

    How are you running your macro?
    If it is from a button on a sheet you may have the properties for the button set to takefocusonclick = true instead of = false

  5. #5
    Registered User
    Join Date
    11-13-2006
    Location
    Sydney Australia
    Posts
    4
    orginally i just made a macro saying

    Sub OpenfrmEmployeeDetails()
        frmEmployeeDetails.Show
    End Sub
    When i opened the sheet, i then clicked on 'run macro' in the Visual Basic toolbar & selected OpenfrmEmployeeDetails()

    This popped up the form & away i went.

    Now i'd like to call the macros, to build the timesheet & run the form, from one macro.

    Thanks

  6. #6
    Registered User
    Join Date
    11-13-2006
    Location
    Sydney Australia
    Posts
    4
    ahhh
    dont worry about me.
    Just realised i was calling the wrong macro.
    i had 'another' macro that 'opened' the input form.
    so
    the solution was

    Sub StartUp()
    OpenfrmEmployeeDetails
    AutoWreckers
    End Sub
    ahh it was so simple its stupid
    Thanks for your help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1