複製一段範圍的儲存格資料到蒐集資料的Sheet中

Re: Macro CopyRange Copy Cells to another Spreadsheet or fil(20170102查詢)修正為如下:

<code>
Sub TableCopyToData rem 此一程式碼是OK的
  Dim oDocA, oSheetA, oSheetB, Dummy(), oRangeA, targetcell as object
  Dim oDispatcher, oFrameA, c as object
  Dim LastRow as long
  oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
  oDocA = ThisComponent
  oFrameA = oDocA.CurrentController.Frame
  oSheetA = oDocA.getSheets.getByName("print")
  oRangeA = oSheetA.getCellRangeByName("c8:i10")
  oDocA.CurrentController.Select(oRangeA)
  oDispatcher.executeDispatch(oFrameA, ".uno:Copy", "", 0, Dummy())
  oSheetB = oDocA.getSheets.getByName("data")
  c = oSheetB.createCursor
  c.gotoEndOfUsedArea(false)
  LastRow = c.RangeAddress.EndRow +1
  targetcell= oSheetB.getCellByPosition(1,LastRow)
  oDocA.CurrentController.Select(targetcell)
  oFrameA = oDocA.CurrentController.Frame

  dim args4(5) as new com.sun.star.beans.PropertyValue
  args4(0).Name = "Flags"
  args4(0).Value = "SVD"
  args4(1).Name = "FormulaCommand"
  args4(1).Value = 0
  args4(2).Name = "SkipEmptyCells"
  args4(2).Value = false
  args4(3).Name = "Transpose"
  args4(3).Value = false
  args4(4).Name = "AsLink"
  args4(4).Value = false
  args4(5).Name = "MoveMode"
  args4(5).Value = 6
rem  oDispatcher.executeDispatch(oFrameA, ".uno:Paste", "", 0, args4())  rem 不可使用Paste,因Paste是全部原封不動的貼上(含公式)。
  oDispatcher.executeDispatch(oFrameA, ".uno:InsertContents", "", 0, args4()) 
End Sub
</code>

arrow
arrow
    文章標籤
    libreoffice Calc marcos
    全站熱搜
    創作者介紹
    創作者 理群 的頭像
    理群

    呂理群的部落格

    理群 發表在 痞客邦 留言(0) 人氣()