Compile Error: Invalid Use of New Keyword (Using Word 2016)
HighTechForms opened this issue ยท 11 comments
Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As Dictionary
Dim json_Key As String
Dim json_NextChar As String
Set json_ParseObject = New Dictionary
It's crashing on the line where it sets json_ParseObject.
Hello,
There is an incompatibility with the dictionary object of Word. Insert "scripting." before the term dictionary.
Example:
Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As scripting.Dictionary
Dim json_Key As String
Dim json_NextChar As String
Set json_ParseObject = New scripting.Dictionary
@StephaneSM thanks for responding. I'll have to investigate why this only occurs in Word, I'll see if there's a good way to fix this at the library level (ideally you wouldn't need to edit anything to get it to work out-of-the-box in Word)
I can confirm this is not limited to Word, but I did manage to narrow down the problem and have a solution. You must make sure that the "Microsoft Scripting Runtime" comes before any of the Microsoft Word references. In other words, the scripting runtime reference must have higher priority in the References list than the other Microsoft references.
I would recommend that the readme be updated to inform users that might make use of any conflicting references.
I can confirm the same issues, changing to scripting.Dictionary
helped
Maintainers: Please change the module to use "New Scripting.Dictionary" anyway.
The full syntax is compatible both with Word and with Excel, whereas "new Dictionary" is compatible only with Excel.
Or at least write about it in the Readme.md, just next to the "add reference to MS Scripting", e.g. "In order to run it in MS-Word, replace any "New Dictionary" with "New scripting.Dictionary". Excel developers should run it as is".
Hello,
There is an incompatibility with the dictionary object of Word. Insert "scripting." before the term dictionary.
Example:Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As scripting.Dictionary Dim json_Key As String Dim json_NextChar As String Set json_ParseObject = New scripting.Dictionary
Hello,
In order to avoid error "Method or data object not found" at json_ParseObject.Item(json_Key)
, dont forget to add "Scripting." in both:
- function type
Private Function json_ParseObject(json_String As String, ByRef json_Index As Long) As Scripting.Dictionary
- and in affectation
Set json_ParseObject = New Scripting.Dictionary
Has anyone made a pull request on this ?
I strongly suggest MoSad85's solution, in other words switch the library to late binding, since early binding is a known source of troubles.
Well, a pull request is done, and up for review.