omegahat / RDCOMClient

GNU General Public License v2.0
77 stars 34 forks source link

DescTools::XLGetRange() fails with sel$Cells() Error: attempt to apply non-function #13

Open hermandr opened 6 years ago

hermandr commented 6 years ago

I am running R version 3.5.0

I have installed the packages:

install.packages("DescTools")
install.packages("RDCOMClient", repos = "http://www.omegahat.net/R")

I have run Excel and selected a range of values. Then I run this code in RStudio:

library(DescTools)
BMI <- XLGetRange(header=TRUE)

I get this error message:

Loading required namespace: RDCOMClient
Error in sel$Cells() : attempt to apply non-function

I checked the source code of XLGetRange()

......
if(is.null(file)){
    xl <- GetCurrXL()
    ws <- xl$ActiveSheet()
    if(is.null(range)) {
      # if there is a selection in XL then use it, if only one cell selected use currentregion
      sel <- xl$Selection()
      if(sel$Cells()$Count() == 1 ){
        range <- xl$ActiveCell()$CurrentRegion()$Address(FALSE, FALSE)
      }
.....

xl <- GetCurrXL() returns

An object of class "COMIDispatch"
Slot "ref":
<pointer: 0x000000000011b688>

xl$ActiveSheet() returns NULL xl$Selection() returns NULL

Your help will be greatly appreciated. Herman

duncantl commented 6 years ago

Hi Herman I hope you've reported this to the author of DescTools. That is the first place to start to see if it is a problem with the logic in that package's function.