PDA

View Full Version : Run Macro From User Form



Giri
06-10-2011, 10:39 PM
Hi Guys,

I am trying to run a macro from a userform but am having some problems. When I select the macro to be run on the user form and then press OK... nothing happens. ATM, I get an error message saying "Expected Function or Variable" for the WorkoutSelector Macro ... although this macro doesn't not take any inputs. When I delete the Workout Selector line of Code.. there are no error messages but the FindCopy Macro doesn't run (a input box should appear).

PS: Both these macros are in other modules and are Public.

Any help would be greatly appreciated!!

Kind Regards,

Giri



Option Explicit

Private Sub Cancel_Click()

Unload Me

End Sub

Private Sub FindCopy_Click()


End Sub

Private Sub Workout_Click()

End Sub

Private Sub OK_Click()

If FindCopy = True Then

Run FindCopy()

End If

If Workout = True Then

Run WorkoutSelector

End If


End Sub

Bob Phillips
06-10-2011, 10:41 PM
WE are only seeing part of the story. Where is the WorkoutSelector macro?

Giri
06-10-2011, 11:17 PM
Hi Xld,

This is the macro.

Giri


Option Explicit



Public Sub WorkoutSelector()

Dim exNo As Integer
Dim Workout As Range
Dim Workout1 As Range
Dim Workout2 As Range
Dim Msg As Range
Dim w1Row As Integer
Dim w1Col As Integer
Dim w2Row As Integer
Dim w2Col As Integer
Dim Giri As Range
Dim ws As Worksheet
Dim animal As Worksheet
Dim TimerCellRow As Integer

Randomize

exNo = Int((6 * Rnd) + 1)

Set Workout = Cells(exNo, 4)

Set Workout1 = Workout.Offset(0, 1)
Set Workout2 = Workout.Offset(0, 2)

w1Row = Workout1.Row
w1Col = Workout1.Column
w2Row = Workout2.Row
w2Col = Workout2.Column

MsgBox "Today's Exercise: " & vbNewLine & Cells(w1Row, w1Col).Value & vbNewLine & "for " & vbNewLine & Cells(w2Row, w2Col).Value

TimerCellRow = Workout.Row


Call Timer(TimerCellRow)

End Sub


Public Sub Timer(TargetCellRow As Integer)

Dim MinsRemaining As Integer
Dim iMins As Integer
MinsRemaining = 1200

For iMins = MinsRemaining To 0 Step -1
Range("I" & TargetCellRow).Value = iMins & " secs"
Application.Wait (Now + TimeValue("0:0:01"))
Next iMins

End Sub

Bob Phillips
06-10-2011, 11:41 PM
But where does that macro exist? Perhaps if you could post the workbook?

Giri
06-11-2011, 12:03 AM
Hi Xld,

Here you go.

6111

Kind Regards,

Giri

Bob Phillips
06-11-2011, 01:06 AM
Sorry, should have spotted that in the code



Option Explicit

Private Sub Cancel_Click()
Unload Me
End Sub

Private Sub FindCopy_Click()


End Sub

Private Sub Workout_Click()

End Sub

Private Sub OK_Click()
If FindCopy = True Then

Call FindCopy
ElseIf Workout = True Then

Call WorkoutSelector
End If
End Sub

Giri
06-11-2011, 02:36 AM
Hi Xld,

I tried what you wrote but I get the error:

"Invalid use of Property", for the "Call" command.

Kind Regards,

Giri

Bob Phillips
06-11-2011, 02:38 AM
What? It worked fine for me.

Giri
06-11-2011, 04:22 AM
Yeah.. that's odd. I'll try and work something out..

Thanks for your help man!!

Kind Regards,

Giri

Bob Phillips
06-11-2011, 06:02 AM
It is odd, and it is a very odd message, the code is very simple.

Paul_Hossler
06-11-2011, 12:36 PM
When I right click on FindCopy and try to go to the Defintion, I get a "F3Dynamic library not referenced' message

Renaming it to Find_Copy, it works

No idea what a F3Dynamic library is

Paul

Paul_Hossler
06-11-2011, 02:32 PM
http://www.vbforums.com/showthread.php?t=442886

Found a little more about it

Paul