如何在VBA中使用数组指针

时间:2018-07-02 19:26:43

标签: arrays excel-vba vba excel

我正在尝试使用Lotus.Range.GetCellData从旧的Lotus 123文件中提取数据,它返回一个long值,该值是一个指针数组,该指针数组用于该范围内的每个单元。 / p>

Dim LotusApp As Lotus123.Application
Dim LDoc As Lotus123.Document
Set LDoc = GetObject("C:\temp\Test.wk3", "Lotus123.Workbook")
Set LotusApp = LDoc.Application
LotusApp.Visible = True
LDoc.Activate

Dim r As Lotus123.Range
Set r = LDoc.Ranges("A:A1..A:D4")
Dim ArrayPointer As Long
ArrayPointer = r.GetCellData

... do something

r.FreeCellData

我真正想要的是VBA中的普通数组,例如Dim arr() as String。那么,如何从指针数组转到具有VBA中值的实际数组?

下面是一个C ++代码示例:

DllExport long TransposeDoub(unsigned long ptr, unsigned long rows, unsigned long cols)

{
   PCellDataHdr hdr = (PCellDataHdr) ptr;
   double *buf = (double *) &hdr[1];
   unsigned int i, j;
   int count = 0;

   // Validate arguments and table. 
   if (rows <= 2 ||
      !hdr->IsDouble ||
      rows > hdr->rows ||
      cols > hdr->cols) {
      return 0;
      }

   for (i = 0; i < cols; i++) {
      double tmp, *pCol;
      pCol = &buf[i * hdr->rows];             // Calc column pointer. 

      // Swap column rows.
      for (j = 0; j < rows/2; j++) {

         tmp = pCol[rows - j - 1];
         pCol[rows - j - 1] = pCol[j];
         pCol[j] = tmp;
         count++;
         }
      }
   return count; 
}

那么我该如何将其转换为VBA?

0 个答案:

没有答案