LibreOffice calc Hyperlink from macro doesn't work - libreoffice

I have trouble making hyperlink within macro.
For example just create empty spreadsheet and create another sheet within so we have 2 empty sheets.
In Sheet1 A:1 just paste =HYPERLINK("#Sheet2")
For A:3 create macro and execute it
Sub TestMacro
dim document as object
oSheet = thiscomponent.sheets.getByName("Sheet1")
oCell = oSheet.getCellRangeByName("$A$3")
xx="=HYPERLINK(""#Sheet2"")"
oCell.setString(xx)
End Sub
So sheet1 now have something on cell A1 and A3. the both should be link but just A1 works.
If jou press CTRL+click on Sheet1 A1 the Sheet2 is selected.
If you press CTRL+click on Sheet1 A3 nothing happens
I tested ou xubuntu 18.04LTS
LibreOffice Version: 6.0.7.3
Build ID: 1:6.0.7-0ubuntu0.18.04.10

For functions and calculations, set the cell formula instead of a literal string value.
oCell.setFormula(xx)

Related

I wish to execute a macro with enter key

I have a macro/Sub that I wish to run everytime the enter key is pressed. Does anyone know the correct syntax?
Excel on Enter Macro
How to run a macro when certain cells change in Excel
Right-click the Sheet1 tab and then click View Code.
The module sheet behind Sheet1 is opened.
Type the following code into the module sheet:
Private Sub Worksheet_Change(ByVal Target As Range) Dim KeyCells As Range. ...
Click Close and Return to Microsoft Excel on the File menu.

LibreOffice Calc - how to drag-fill a series from multiple rows that all reference the same row

I have cells in a few rows that all reference one row on another sheet:
=Sheet2.A1
=Sheet2.B1
=Sheet2.C1
When I select these cells and drag the fill handle to fill the cells below, Calc fills them like this:
=Sheet2.A4
=Sheet2.B4
=Sheet2.C4
=Sheet2.A7
=Sheet2.B7
=Sheet2.C7
etc.
I guess it's doing this because each new row is three cells below the original row.
This is not the behaviour I want - I want to fill them in a series, like this:
=Sheet2.A2
=Sheet2.B2
=Sheet2.C2
=Sheet2.A3
=Sheet2.B3
=Sheet2.C3
=Sheet2.A4
=Sheet2.B4
=Sheet2.C4
etc.
Any ideas how to do this?
I'd like to use either a formula or a manual way of doing this - I'm not familiar with macros so would rather avoid if possible, please.
Manual way (I like that suggestion, I never even thought about using Calc to automatize the process of filling in spreadsheet formulas before, but it's doable):
Open a new Calc file
Format cell A1 as text
type =Sheet2. into A1 (A1 should now display =Sheet2. literally)
type A B C into B1, B2 and B3 respectively
select B1 to B3 and drag down (it should repeat series A,B,C,A,B,C...)
type =FLOOR((ROW()-1)/3)+2 into C1 (ROW() starts counting from 1 hence the -1)
drag that down (it should give you the series 2,2,2,3,3,3,4,4,4...)
type =A$1&B1&C1 into D1 (D1 should now display =Sheet2.A2 literally)
drag D1 down and it should give you your desired series
NOW: copy that
paste it into any notepad or similar plain text editor
copy that
paste it into the Calc spreadsheet you wanted to have this series of references in first place
it should open a text import dialogue - just make sure everything is pasted into one column and hit OK
VoilĂ 
pros: when your colleagues see you do that you will be seen as LibreOffice god from now on
cons: not very dynamic (you'll have to repeat the whole process if something changes)
Formula way:
Use OFFSET.
E.g: =OFFSET(Sheet2.$A$2;FLOOR((ROW()-1)/3);MOD(ROW()-1;3))
pros: easier to modify
cons: if the results are not what you're expecting, it's harder to debug

How to apply conditional format to odt file?

I need to evaluate a cell on a table on a odt, file, and apply conditional format if value is > 0.
Not in speedsheet, is for writer
Tested with LO 5.4 and 6.0.4 on Win 10:
IMHO, the best solution is to insert a LO Calc spreadsheet as "OLE Object" into the odt file. This gives you the complete Calc funtionality inside Writer.
To do so, put the cursor to where the table should appear. Select Menu "Insert" -> "Object" -> "OLE Object". In the following window, select "New" and "LibreOffice 6.0 Spreadsheet". Alternatively, you may insert an already-existing Calc table.
After clicking OK, the object will appear, and it's already activated (you can determine if it's active by the thick gray border and the row/column heads - you can "deactivate" it by clicking outside, anywhere in the Writer document; you can re-activate the Calc object by double-clicking inside its borders).
Now, you can edit the Calc table as usual. Notice that the Menus will adapt to the Calc features if the Calc OLE object is active. So, e.g. the "Format" Menu will only contain a "Conditional formatting" entry if the Calc OLE object is active.
Here are some screenshots:
Insert a OLE object in Writer:
Writer document with embedded Calc table:
Applying conditional formatting to some content of the embedded Calc sheet:
Resulting Writer document with conditionally-formatted Calc table (Calc object is active):
Same as 4, now Calc object is inactive:

Change the caption in a form in VBA

I have created 2 forms in excel, userform1 and userform2. How do I set the caption of userform2 so that it displays whatever is in textbox1 of userform1 and updates itself when the value of textbox1 changes?
As Rory mentioned here just add it to the UserForm1 TextBox1 Change Sub.
Paste the script below into the code part of UserForm1.
Private Sub TextBox1_Change()
'Assign the TextBox Text to a variant
SomeText = TextBox1.Text
'Set the UserForm2 Caption to the variant
UserForm2.Caption = SomeText
End Sub
To paste the script into the code part of your UserForm, double click the Userform in the left side Window of VBA called "Projects Window" then press F7 button on your key board to access the code part of the UserForm then paste the code into the bottom of the page.

Macro to paste value on row's based on column date

I have in sheet1 a cell A1 where I put in a date (DD/MM/YYYY) in cell B2 is a number the info in cell A1 and B1 change but macro will always copy from B1. On sheet2 on column A are the dates(DD/MM/YYYY) for the whole year one under the other, I want a macro that based on the date in cell A1 on sheet1 looks on sheet2 on column A and copy/pastes the info from B2 on column B from sheet2 on same row with the according date in column A.
I looked around for similar things but couldn't find anything to work any help is appreciated.
Thank you in advance.
So far I used a pretty simple copy paste macro but using this means I have to write it over and over again for each day of the year.
Where C1 = A1 in Sheet2 witch is first date
Sub test()
**Sheets("Sheet1").Select
If Range("A1") = Range("C1") Then
If Range("B1").Value > "0" Then
Range("B1").Copy
Sheets("Sheet2").Select
Range("B1").PasteSpecial xlPasteValues
else
end if
else
end if
end sub
So doing it like this I would have to write it again and again for C2..C3.. and put paste to B2.. B3 etc so im looking for a solution to write it just once to look in whole column and paste on the according row.