Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range.Columns property error encountered after upgrading to new version of exceldna #705

Open
godefy opened this issue Jul 20, 2024 · 4 comments

Comments

@godefy
Copy link

godefy commented Jul 20, 2024

ClassLibrary1_vb_testRange.zip

I recently encountered a problem using the latest version
When the range object uses the Columns attribute, it cannot be used normally.

Range.Columns Property (Microsoft.Office.Interop.Excel) | Microsoft Learn

I used to use "rangeObj.Columns(1)" to get the first column of data in the range, but now when I use the same code, an exception occurs: "System.MissingMemberException"
Previously the following code worked fine:
dim result = rangeObj.Columns(1).value
Now i can only:
Dim temp = rangeObj.Columns(1)
dim result = temp.value

This problem feels very strange to me. This is the only problem I have left after upgrading to the new version. Please help me confirm the reason.

I've attached the project I used. Excel input during debugging:
Snipaste_2024-07-19_19-52-26

@godefy
Copy link
Author

godefy commented Jul 20, 2024

I tried it again just now and found that the root cause of this problem seems to be not only the Columns attribute, but also the index of the range.
Normally, for the range object rng
The following code can directly get the specified item in the range object (it was also normal in my previous exceldna project using version 0.34):
rng(1)
rng.Item(1)

Currently, running the above code can indeed obtain an object, but this object is not a valid range object, and attributes such as .count or .address cannot be obtained from it.

In addition, now I get a range object directly and an error will be reported:
Dim e = ExcelDnaUtil.Application.Range("$C$1")
(Similarly, it was also normal in my previous exceldna project using version 0.34)

@godefy
Copy link
Author

godefy commented Jul 20, 2024

I wrote an example in the attachment that more directly reflects the root cause of the problem. Please help me take a look:
Function xRangeTest(rng As Range) As Object
Dim d = rng.Item(1).address 'will false
Dim d1 = rng.Item(1).count 'will false
Dim e = ExcelDnaUtil.Application.Range("$C$1") 'will false

End Function

ClassLibrary1_vb_testRange.zip

@godefy
Copy link
Author

godefy commented Jul 20, 2024

I tested it many times and finally found a way to get the specified range items normally.
That is, rng(1) must be explicitly assigned to a range variable:
Dim a As Range = rng(1)
Then you can use:
a.Address

If you directly use chain calls or implicit definitions, you will not be able to obtain the corresponding attributes normally:
rng(1).Address 'will false
or:
Dim a = rng(1)
a.Address 'will false

I don't know why this happens when I use the new version of exceldna library in my new project. I didn't encounter this problem in the old project.

@godefy
Copy link
Author

godefy commented Jul 20, 2024

The same is true for range.Worksheet.Parent.Name, and chain calls cannot be made.
A temporary variable must be explicitly declared before its properties can be called
dim a as workbook = range.Worksheet.Parent
a.Name

I don’t know if there’s something wrong with my usage, or if it’s just like this in the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant