6diegodiego9
Board Regular
- Joined
- Jan 9, 2018
- Messages
- 80
- Office Version
- 2016
- Platform
- Windows
I use the following trick to use Selenium in my VBA code without requiring installation nor registration of the Selenium files on the target PCs:
Now, as an additional optimization step I'd like to convert the code inside CreateObjectSelenium to only use late bindings, so that you don't need to set the two references when copying the code from my message(s), and as "best practice" of converting everything to "late binding" when deploying code to public.
However my first attempt to convert that to late binding using the usual "as object" and "createObject("xxxx.yyyyyy") failed with unexpected errors.
It appears that "as mscorlib.AppDomain" and "as mscoree.CorRuntimeHost" could not be simply substituted by "an object" or "as variant".
Any ideas about how to convert those to late bindings?
VBA Code:
Function CreateObjectSelenium(strTypeName As String) As Object
'Required references: Mscoree (taken from C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoree.tlb) and mscorlib
Static domain As mscorlib.AppDomain
If domain Is Nothing Then
With New mscoree.CorRuntimeHost
.Start:
.GetDefaultDomain domain
End With
End If
Set CreateObjectSelenium = domain.CreateInstanceFrom(ThisWorkbook.path & "\SeleniumBasic\Selenium.dll", strTypeName).Unwrap
End Function
Sub esempio()
Dim oEdge As Object 'Selenium.EdgeDriver
Set oEdge = CreateObjectSelenium("Selenium.EdgeDriver")
With oEdge
.Start "edge"
.Get "https://www.esempio.it"
msgbox "pausa"
.Quit
End With
End Sub
Now, as an additional optimization step I'd like to convert the code inside CreateObjectSelenium to only use late bindings, so that you don't need to set the two references when copying the code from my message(s), and as "best practice" of converting everything to "late binding" when deploying code to public.
However my first attempt to convert that to late binding using the usual "as object" and "createObject("xxxx.yyyyyy") failed with unexpected errors.
It appears that "as mscorlib.AppDomain" and "as mscoree.CorRuntimeHost" could not be simply substituted by "an object" or "as variant".
Any ideas about how to convert those to late bindings?