0

I have a workbook with two worksheets say simply 1 and 2. Worksheet 1 has a button that when clicked, runs a VBA sub to call an R script. Using the package RDCOMClient, the R script connects to the (still open) workbook, reads some data tables off sheet 1, computes some stuff and then outputs a data table t. What I want to do is output t to sheet 2.

What I currently do:

for (i in seq(t[,.N])){
    for (j in seq(length(t))){
        ws$Cells(i,j)[["Value"]]<-t[[i,j]]; #ws is a reference to Sheet2
    }
}

Now the problem with this is that it's insanely slow. It takes like 1-2 minutes to write a 60x130 table. Does anyone know how to make this faster?

PS: I want to update an open workbook, not save to a different file. So that's why I didn't try something like openxl etc.

4

0 回答 0