VBA Questions...

#1
These questions were made in the Spanish forum, but VBA is out of my knowledge, so if anyone can answer please, then I'll translate to Spanish, thanks in advance...

1) "How I can associate the execution of a macro in VBA to an option of menu '. It is to say: I want that when selecting a menu option, executes one of my macros. I have tried it with DefineFunction, and when it is executed, it executes the VBA. function Later, if attempt to execute it from the line of commandos in the form (macro name) does not do anything, or, if the function gives back a value, it leaves the program directly."

2)"User forms: I must show a dialogue in my application. I do it with VBA, to have more control on events... but it does not let to me modify the size of the form. So that '. "

Well, thank you very much

#2
Alberto,

Item 1
To execute a macro from a toolbar or a menu use:

^C^C^C(command "-vbarun" "ModuleName.MacroName")

Notice the "-" sign in front of the vbarun.

If you want to repeat the command use:
^C^C^C(defun C:AnyName(command "-vbarun" "ModuleName.MacroName"));AnyName

This defines the menu item as a command and you can right click your mouse button or press enter to repeat the macro.

Item 2
Do you want to control the form size at run time or design time?



------------------
Regards
John Finlay

#4
Yolanda,

If your form name is UserForm1

Place the code in the your Module:

UserForm1.Height = 300
UserForm1.Width = 300
UserForm1.Show


------------------
Regards
John Finlay

#5
John,

I'm sorry, but I didn't explain myself properly: I need that the user can change the size of the form showed. I can't do it now, why?

Thank you very much in advance.

#6
Yolanda,

It's the same method.

Open a new drawing.
Open VBA IDE
Insert a new UserForm (default UserForm1)
Insert two command buttons named cmdDouble and cmdHalf

Double click on a command button.

copy and paste code below in UserForm1 module:-

Option Explicit

Private Sub cmdDouble_Click()

UserForm1.Height = UserForm1.Height * 2
UserForm1.Width = UserForm1.Width * 2

MsgBox "The UserForm1 Height =" & UserForm1.Height _
& vbCr & "The UserForm1 Width =" & UserForm1.Width

End Sub

Private Sub cmdHalf_Click()

UserForm1.Height = UserForm1.Height / 2
UserForm1.Width = UserForm1.Width / 2

MsgBox "The UserForm1 Height =" & UserForm1.Height _
& vbCr & "The UserForm1 Width =" & UserForm1.Width
End Sub

Now run the Form and see how it doubles when you click the Double command button and it halfs when you select the Half command button.




------------------
Regards
John Finlay

#7
Yolanda,

Another method is to add the following to a form, it will make the lower right hand corner of the form a hot spot which can be dragged with the mouse to resize.

'Begin Code

Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTBOTTOMRIGHT = 17
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim lngHwnd As Long
If X >= Me.Width - 10 Then
If Y >= Me.Height - 30 Then
lngHwnd = FindWindow(vbNullString, Me.Caption)
ReleaseCapture
SendMessage lngHwnd, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, ByVal 0&
End If
End If
End Sub

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If X >= Me.Width - 10 Then
If Y >= Me.Height - 30 Then
Me.MousePointer = fmMousePointerSizeNWSE
End If
Else
Me.MousePointer = fmMousePointerDefault
End If
End Sub

'End code


hope this helps,

Scott
cron