LibreOffice Version: 7.6.7.2 (X86_64) / LibreOffice Community
Build ID: dd47e4b30cb7dab30588d6c79c651f218165e3c5
CPU threads: 8; OS: Windows 10.0 Build 22631;
This macro to copy a cell’s contents sometimes works, sometimes doesn’t.
I have 10 sheets in my workbook. The macro copies a cell in Sheet1 to the clipboard. Where am I going wrong? Where may it work differently depending on which sheet is currently selected or which cell? I’d like it to work the same no matter the current sheet or cell when the macro is called.
Thank you in advance.
(Edit -updated code for simplicity)
Sub BCopyToClipboard()
Dim oSheet As Object, oCell As Object, oDispatcher As Object, oFrame As Object
oSheet = ThisComponent.Sheets.getByName("Sheet1")
ThisComponent.getCurrentController().setActiveSheet(oSheet)
oCell = oSheet.getCellRangeByName("F1")
ThisComponent.getCurrentController().select(oCell)
oFrame = ThisComponent.getCurrentController().getFrame()
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatcher.executeDispatch(oFrame, ".uno:Copy", "", 0, Array())
End Sub