调整LotusScript范围

时间:2014-01-14 17:28:35

标签: lotusscript lotus

使用Lotus 123 for Windows 1997(是的很老)

我正在尝试在Excel中做什么VBA是一件非常简单的事情;偏移和调整大小。但我被困在LotusScript中。

'this works fine in Excel
Dim ws As Worksheet
Dim rg As Range
Set ws = ThisWorkbook.Worksheets(1)
Set rg = ws.Range("MyRange").Offset(0, 1)
Set rg = rg.Resize(rg.Rows.Count, rg.Columns.Count - 1)

'how to complete this in LotusScript?
Dim DocLotus As Lotus123.Document
Set DocLotus ...
Dim rg As Lotus123.Range
Set rg = DocLotus.Ranges("MyRange")

'offset one column to the right

'resize one column less
你能帮帮我吗?我正在阅读帮助文件,但找不到合适的方法。

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

我最终想出了一种复制Excel调整大小方法的方法,尽管不完全正确。这并没有超出SrcRange的终点,但这对我的要求来说还不错。

Function Resize(SrcRange As Range, ByVal RowCount As Integer, ByVal ColumnCount As Integer) As Range

    'this function resizes the range but cannot go beyond the end of SrcRange
    Dim StartCell As Range
    Dim EndCell As Range
    Set StartCell = SrcRange.cell(0, 0)
    Set EndCell = SrcRange.cell(RowCount - 1, ColumnCount - 1)

    Dim LeftAddr As String
    Dim RightAddr As String
    LeftAddr = Left(StartCell.CoordinateString, InStr(StartCell.CoordinateString, "..") + 1)
    RightAddr = Left(EndCell.CoordinateString, InStr(EndCell.CoordinateString, "..") - 1)

    Dim NewRange As Range
    Set NewRange = SrcRange.Parent.Ranges(LeftAddr & RightAddr)
    Set Resize = NewRange

End Function

这是OffSet方法,但它不会超出SrcRange的末尾

Function OffSet(SrcRange As Range, ByVal byRow As Integer, ByVal byColumn As Integer) As Range

    'this function offsets the beginning of the range but does not go beyond the end of SrcRange
    Dim StartCell As Range
    Dim EndCell As Range
    Set StartCell = SrcRange.Cell(byRow, byColumn)
    Set EndCell = SrcRange.Cell(SrcRange.EndRow - SrcRange.StartRow, SrcRange.EndColumn - SrcRange.StartColumn)

    Dim LeftAddr As String
    Dim RightAddr As String
    LeftAddr = Left(StartCell.CoordinateString, InStr(StartCell.CoordinateString, "..") + 1)
    RightAddr = Left(EndCell.CoordinateString, InStr(EndCell.CoordinateString, "..") - 1)

    Dim NewRange As Range
    Set NewRange = SrcRange.Parent.Ranges(LeftAddr & RightAddr)
    Set OffSet = NewRange

End Function

要将这些扩展为与Excel完全相同的功能,我想我需要像这样的Cell函数;但这又是不完整的,因为它只适用于第一张纸。

Function Cells(RowNum As Long, ColNum As Long)
    Dim rg As Range
    Set rg = CurrentDocument.Ranges("A:A1..A:IV8192")
    Set rg = rg.Cell(RowNum - 1, ColNum - 1)
    Set Cells = rg
End Function

希望这有助于某人。