-
Apr 21st, 2018, 02:17 PM
#1
[RESOLVED] CallByName and Late-Binding
Wow, apparently, in the VBA, you can't use CallByName with late-bound object, unless I'm just blind and overlooking something.
Here's some code I put into a UserForm1:
Code:
Option Explicit
Public Sub Testing()
MsgBox "got to testing"
End Sub
And here's some code I just threw into a Module1:
Code:
Option Explicit
Private Sub EarlyBoundWithCallByName()
CallByName UserForm1, "Testing", VbMethod
End Sub
Private Sub LateBoundWithCallByName()
Dim frm As UserForm
'
Set frm = UserForm1
CallByName frm, "Testing", VbMethod
End Sub
If I execute EarlyBoundWithCallByName, everything works fine. However, if I execute LateBoundWithCallByName, I get the following error.
Hmmm, that's pretty sad.
Y'all Take Care,
Elroy
EDIT1: Just for grins, I made sure the form was loaded and showing first, but it didn't make any difference. Same results. Here's how I modified my Module1 test code:
Code:
Option Explicit
Private Sub EarlyBoundWithCallByName()
UserForm1.Show 0
CallByName UserForm1, "Testing", VbMethod
End Sub
Private Sub LateBoundWithCallByName()
Dim frm As UserForm
'
UserForm1.Show 0
Set frm = UserForm1
CallByName frm, "Testing", VbMethod
End Sub
Last edited by Elroy; Apr 21st, 2018 at 02:24 PM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Apr 21st, 2018, 02:57 PM
#2
Re: CallByName and Late-Binding
Errr.....?
Shot in the dark
The Latebound-Function:
You're declaring frm inside the function (scope), but you're not creating it (no Set frm=New UserForm1), and you're loading USerForm1, not frm.
But, as i said: A shot in the dark
EDIT: Just saw your EDIT...... :-(
EDIT2: Found something:
https://stackoverflow.com/questions/...-ihtml-element
You could try:
Code:
Dim frm As IUnknown
Set frm = UserForm1
CallByName frm, "Testing", VbMethod
Last edited by Zvoni; Apr 21st, 2018 at 03:10 PM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Apr 21st, 2018, 04:27 PM
#3
Re: CallByName and Late-Binding
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Apr 21st, 2018, 04:36 PM
#4
New Member
Re: CallByName and Late-Binding
Hello Elroy,
This worked for me. I set the ShowModal property to False before running the code.
Code:
Sub TestA()
UserForm1.Show
CallByName UserForm1, "Test", VbMethod
End Sub
Sub TestB()
Dim frm As Object
Set frm = UserForm1
frm.Show
CallByName frm, "Test", VbMethod
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|