Con Excel, tratando de encontrar un rango genuino usado de HTA externo
He estado usando este comando:
LastRow = ActiveSheet.UsedRange.Rows.Count
Pero la propiedad UsedRange a menudo puede ser inexacta. Entonces estoy buscando una alternativa. Encontré un gran consejo para explicar este método:
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Esto funciona de maravilla en Excel. Sin embargo, estoy ejecutando código de una HTA, por lo que necesito convertir esta línea y estoy luchando. Esta es mi pregunta --- ¿alguien puede ofrecer orientación sobre cómo convertir este código simple en uno compatible con HTA?
Por interés, para tratar de sortear este problema, intenté escribir una rutina de una manera que yo entienda. El resultadotrabajos, pero es muy lento. Aquí está para las risas:
Set objExcel = GetObject(,"Excel.Application")
wb = "test.xlsx"
objExcel.Workbooks(wb).Activate
wbactiveSheet = objExcel.Workbooks(wb).ActiveSheet.Name
'determine rows and columns in range of first xls
theNumRow = objExcel.Workbooks(wb).Sheets(wbactiveSheet).UsedRange.Rows.Count
theNumCol = objExcel.Workbooks(wb).Sheets(wbactiveSheet).UsedRange.Columns.Count
'determine genuine used rows:
x = 1 'start at first row
blankRows = 0
Do 'each row
y = 1 'start at first column
blankCells = 0
Do 'each column
If objExcel.Workbooks(wb).Sheets(wbactiveSheet).Cells(x, y).Value <> "" Then
theNumRowActual = x
'found non-blank, skip to next row
Exit Do 'the columns loop
Else
blankCells = blankCells + 1
End If
y = y + 1
Loop Until (y - 1) = theNumCol
If blankCells = theNumCol Then 'blank row
blankRows = blankRows + 1
If blankRows = 50 Then
Exit Do
End If
Else
blankRows = 0
End If
x = x + 1
Loop Until x = theNumRow 'i.e. until the testing area matches the usedRange property
'determine genuine used columns:
y = 1 'start at first column
blankCols = 0
Do 'each column
x = 1 'start at first row
blankCells = 0
Do 'each row
If objExcel.Workbooks(wb).Sheets(wbactiveSheet).Cells(x, y).Value <> "" Then
theNumColActual = y
'found non-blank, skip to next column
Exit Do 'the rows loop
Else
blankCells = blankCells + 1
End If
x = x + 1
Loop Until (x - 1) = theNumRowActual
If blankCells = theNumRowActual Then 'blank column
blankCols = blankCols + 1
If blankCols = 50 Then
Exit Do
End If
Else
blankCols = 0
End If
y = y + 1
Loop Until (y - 1) = theNumCol 'i.e. until the testing area matches the usedRange property
'bug
MsgBox "USEDRANGEMETHOD:" &vbNewLine & "rows: " & theNumRow & vbNewLine & "columns: " & theNumCol & vbNewLine & vbNewLine & "NEWMETHOD:" & vbNewLine & "rows: " & theNumRowActual & vbNewLine & "columns: " & theNumColActual
Gracias