Closed MitsOmitsaras closed 1 year ago
@MitsOmitsaras thank you for the report. I have made some tweaks based on your valuable findings in v2.7.3. Would you be able to help check if the new framework version is compatible with Word & Access at your end out-of-the box?
Once again I would like to thank you for sharing this work with us. This is endless and very useful for people like me, that need browser automation but cannot install any software. Also very handy. I will try it the soonest and be back with the results.
After importing the 4 CDP classes in a new word document, and adding a reference to the Microsoft Scripting Runtime library.
The Dictionary class of the Microsoft Scripting Runtime library fails in the following points: A) CDPBrowser class Module declarations section: Private varIDs As Dictionary Function invokeMethod(...) As Dictionary Function sendMessage(strMessage As String, Optional objAllMessages As Dictionary ...) Function invokeError(result As Dictionary)
B) CDPJconv class Function json_ParseObject(...) As Dictionary
C) CDPElement class Module declarations section: Private varIDs As Dictionary
After changing at these points every Dictionary to Scripting.Dictionary, the code compiles successfully.
However the remaining "simply mentioned" Dictionaries fail at runtime due to type mismatch.
Function sendMessage
needs to be turned into:
sendMessage(strMessage As String, Optional objAllMessages As Dictionary ...) As Scripting.Disctionary.
Also the variable params
of the Function invokeMethod
.
Also the variable targetObjIdCol
of the Sub init
in the CDPElement class.
I must say that this failing of the Dictionary class feels like some kind of built in error of the Microsoft Scripting Runtime library when used with MS Word, rather than an error raised by your particular code. May I suggest this. What about making this change (Dictionary to Scripting.Dictionary) to every point of this code just to be sure. Anyway you know better.
Everything works fine.
After importing the 4 CDP classes in an existing access project (accdb), already having a reference to the Microsoft Scripting Runtime library, the MS Word library and the MS Excel library.
The ThisWorkbook
variable in the Sub Class_Initialize
of the CDPBrowser class raises a run-time error '1004': Method 'ThisWorkbook' of object '_Global' failed.
I wasn't able to understand why. Declaring the variable has stopped this error raising though.
Just a Dim ThisWorkbook
.
2.7.4 now applied with your recommendations above Mits. These are great recommendations and well done on finding these solutions too.
I 've tested the new files. Unfortunately my suggestion for the last compat issue for Access, was a bad approach.
Dim ThisWorkbook
does the trick in my case, but creates another problem if used in Excel.
This is what I 've found out:
Your initial code without Dim ThisWorkbook
works fine with all 3 apps.
The run-time error '1004': Method 'ThisWorkbook' of object '_Global' failed
that I reported to you,
only occurs in Access (or Word) if the Microsoft Excel 16.0 Object Library is added.
In this case, if Dim ThisWorkbook
is added, stops this error.
But this line creates the following error if used in Excel.
Just declaring ThisWorkbook while in Excel, causes it to be empty in Sub Class_Initialize
's scope, so the first case in the Select Case is never executed and the thisApp variable remains empty too.
This raises a run-time error '91': Object varable or With block variable not set
on thisApp when starting a CDPBrowser object.
Everything else works perfect in any case. Sorry for the poor suggestion.
No prob Mits. Certain things can only be found out when it happens. I changed the lines to this and they are all ok. 2.7.4 has been re-uploaded.
Select Case True
Case InStr(Application.name, "Excel"): Set thisApp = ThisWorkbook
Case InStr(Application.name, "Word"): Set thisApp = ThisDocument
Case InStr(Application.name, "Access"): Set thisApp = CurrentProject
End Select
Now that is a really clean and simple solution! All tested. Compiles and runs perfect in any app and any combination of these libraries. Once again thanks for the life saving work you shared with us. Thanks for the reference too. This was very kind.
Let me know if I can help with anything else.
Since you encourage help in pointing bugs, I would like to report some little issues. 1) There is a slight typo in
Property Get varResult
of theCDPelement
class. Instead ofvarResut = varType
the correct should bevarResult = varType
2) When importing the 4 classes in Access instead of Excel, some issues occur on compiling. i) Sometimes there seems to be some kind of "class overlapping" when the "Microsoft Word 16.0 Object Library" is also added before "Microsoft Scripting Runtime" library, but not always. The result is that theDictionary
class raises an error pointing at theNew
keyword of theDictionary
instantiations. This is solved by turning everyDim x As Dictionary
declaration intoDim x As Scripting.Dictionary
, and everySet x = New Dictionary
instantiation intoSet x = New Scripting.Dictionary
. ii) In thecleanUpSessions
function of theCDPBrowser
class, using the word "proc" as a variable, raises an error. I just turned proc to proc1 and everything worked fine. iii)Thisworkbook
object that is mentioned in a couple of places, has to be turrned intoCurrentProject
object and everything works fine.