> Version: 2004
> Operating System: Mac OS X 10.4 (Tiger)
> Processor: Power PC
>
> Hello Everyone, <br><br>I'm working on Excel 2004. <br><br>I've created a
> UserForm in VBA with one TextBox and 2 (two) CommandButtons (Proceed and
> Cancel). On my spreadsheet, I created a button thanks to the "Form"
> toolbar. <br>
There are many ways to do this, but here's one way...
Assume:
1) A form button on the sheet associated with the macro ShowForm()
(Ctrl-click the button and choose Assign Macro... from the
contextual menu)
2) A Userform named MyForm that contains three controls:
a) Command button cbProceed
b) Command button cbCancel
c) Text box tbInput
In the Userform code module:
Option Explicit
Dim bCancel As Boolean 'set if user presses Cancel button
Property Get Cancel() As Boolean
'Retrieve whether user pressed cancel button or not
Cancel = bCancel
End Property
Property Get InputReturn() As Variant
'Retrieve the value entered in the text box
InputReturn = tbInput.Value
End Property
Private Sub UserForm_Initialize()
bCancel = False
End Sub
Private Sub cbCancel_Click()
bCancel = True
Me.Hide 'don't unload the form yet
End Sub
Private Sub cbProceed_Click()
Me.Hide 'don't unload the form yet
End Sub
This goes in a regular code module:
Option Explicit
Public Sub ShowForm()
Dim fmForm As MyForm 'Object variable for form
Set fmForm = New MyForm 'create new instance of the form
With fmForm
.Show
If Not .Cancel Then
Range("T11").Value = .InputReturn
MyMacro
End If
End With
Unload fmForm 'don't unload the form until done with it.
Set fmForm = Nothing 'destroy the object
End Sub
Public Sub MyMacro()
'Do something here
MsgBox "My Macro Ran"
End Sub
> Hello, <br><br>All I can is SWEET! It works just as I wanted. The end part
> does not work thought. The message who's supposed to pop up saying that the
> Macro has run simply doesn't appear. Correct me if I am wrong, but under:
> "Range("T11").Value = .InputReturn" I have to copy/paste
> the macro I made, and at "Public Sub MyMacro()" I have to replace
> "MyMacro" by the name of the macro I copy/pasted just before ?
> <br><br>Is there any possibility to include a progress bar instead ? Not sure
> why the Macro takes up to 20 seconds to run on a Mac while on a PC is nearly
> instantaneous... <br><br>In any case I have to thank you for having taken the
> time to help me. <br><br>All the best. <br><br>Paul
I can barely read your post since it's in HTML, but no, you don't paste
your macro into that line of code, it should stand alone.
If I've misinterpreted - Is your macro in a regular code module?
> Not sure why my post is unreadable...
not your fault at all - but this last one is simply indecipherable for
me. I read the newsgroups with a newsreader, but the web interface turns
spaces into s, ampersands to &s, and quotation marks into
"s.
Perhaps someone who reads the group with a web browser will be able to
help.