Professional Documents
Culture Documents
C A L C M AC RO S
This tutorial will cover on how to create a basic LibreO ce Dialog and
adding various controls such as TextBox. Also it covers on how to read the
control values using Calc Macros.
Adding a Dialog
To add a Dialog in LibreO ce Calc, select from menu: Tools -> Macros ->
Organize Dialogs…
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Create a New Dialog
On the New Dialog pop-up , give a name to your dialog. For this tutorial, lets
keep it as default Dialog1. Press OK.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
New Dialog
You can see the Dialog1 is come up under My Dialogs -> Standard -> Dialog1.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Create Dialog from Menu
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Edit Dialog
Entire Dialog editor would open inside LO Calc. Now its time to add some
controls. For simplicity, I would add a textbox and a button.
The controls are placed at the bottom of the screen. Select a control and
drag your mouse inside the Dialog to place your desired control. For this
tutorial, add a textbox and a button. If you are unable to see the toolbox at
the bottom of the screen, select from menu: View -> Toolbars -> Toolbox.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
The Dialog should look like this now.
The Dialog
To set the properties of each controls, click/select the control, then you can
see the properties window opened on the bottom-le side of the editor. On
the properties window, the ‘name’ value of the General tab would be used to
identify the objects inside Macro.
For textbox the default name is: TextField1, for the button it is:
CommandButton1.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Dialog with Properties
Now, we are all set with the Dialog, for now. Lets write the macro.
The Macro
Using a LO Calc macro, I will show how to open the dialog, read the contents
of the textbox and some content from Calc cell from sheet1. Then show the
content of the textbox and contents from Cell as a message box prompt
while the button is clicked.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Go to the macro editor (click the Module1 tab) and create two functions as
below.
Tip: Read the tutorial on how to create a Macro
Sub StartDialog1()
' Code for initiating and showing the dialog
End Sub
Sub readDialog1()
' Read the content
End Sub
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
SEE ALSO: Use Open File Dialog using Macro in
LibreO ce/OpenO ce
For this tutorial, we will use the OpenO ce/LibreO ce prede ned library
“Tools” with below code. LoadLibrary property will load the Tools library
and then using LoadDialog() function and Execute function we will show the
created Dialog.
Sub StartDialog1()
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
oDialog1.Execute()
End Sub
Alternate Code
Using below snippets also, a dialog can be opened.
DialogLibraries.LoadLibrary("Standard")
oDialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
Now its time to read the content of TextBox and 1st cell of Sheet1 of Calc i.e.
A1. To get a hold of a control, use GetControl( controlName ) function of the
dialog object. Once the object is ready, you can use various properties
available. To get the text entered in the textbox, use control’s Text() property.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Sub readDialog1()
Dim cell_val
oT1 = oDialog1.GetControl("TextField1")
cell_val = ThisComponent.Sheets(0).getCellByPosition(0,0)
msgbox cell_val.String & chr(13) & "Value from controls: " & oT1
End Sub
Tip: Click here to learn more on how to assign a macro to a form control /
button.
Run
Put any text in Calc sheet1’s cell A1 – for this tutorial, I have put “Hello
World”.
Open the Macro editor and run the function StartDialog1(). The dialog
would execute and popup. Now, put some text on the text box and click the
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
button. You should see the text from the textbox from the dialog as well as
from the Calc sheet1’s A1 cell.
This way, you can work with dialogs and controls via basic Macro in
OpenO ce/ LibreO ce Calc.
Video
Watch the video of this tutorial.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Watch on
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Complete Macro
To run, Copy and paste this entire code block below in Macro Editor of
LibreO ce.
Sub StartDialog1()
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
oDialog1.Execute()
End Sub
Sub readDialog1()
Dim cell_val
oT1 = oDialog1.GetControl("TextField1")
cell_val = ThisComponent.Sheets(0).getCellByPosition(0,0)
msgbox cell_val.String & chr(13) & "Value from controls: " & oT1
End Sub
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
LibreO ce Macro Tutorial Index
We bring the latest happenings in the Linux universe, app reviews, tutorials,
easy to understand guides for you. Stay in touch via Telegram, Twitter,
YouTube, and Facebook and never miss an update!
Also Read
M AC RO
Arindam
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Creator of debugpoint.com. All time Linux user and open-
source supporter. Connect with me via Telegram, Twitter,
or send us an email.
Related Posts
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
LibreO ce Macro Read Selected Text and
Organization Select Part of Text in
DECEMBER 17, 2020
TextField Control Using
LibreO ce Basic Macro
MARCH 19, 2020
Subscribe
{} [+]
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
15 COMMENTS Newest
Arthur Szász
4 years ago
it is worth mentioning that when I copy-pasted the bellow code and got a message with
sintax error
“`
Sub StartDialog1()
BasicLibraries.LoadLibrary(“Tools”)
oDialog1 = LoadDialog(“Standard”, “Dialog1”)
oDialog1.Execute()
End Sub
“`
0 Reply
Arindam Giri
Reply to Arthur Szász 4 years ago
0 Reply
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
How to Setup Internet in CentOS, RHEL, Rocky Linux Minimal Install
Rocky Linux 8.4 is here As First Stable Version. Recap and Download
Details.
More on Macro
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Uroš Grum
5 years ago
I cant run this code … im really frustrated with libre o ce as i have been trying since
friday to do something that would take me litteraly 10 minutes in excel. But back to my
problem :
“oT1 = Dialog.GetControl(“TextField1″)”
at the upper part of code i get object variable not set, error i have everything the same,
i even tried to change the name of said control but no di erence. Anny sugestions ?
0 Reply
Arindam Giri
Reply to Uroš Grum 5 years ago
I am assuming that you are using the same example I had here.
In my example the dialog object name is “oDialog1”. In your statement you have
mentioned “Dialog”. You should be using the dialog object name that you de ned in
GetControl.
oT1 = oDialog1.GetControl(“TextField1”)
0 Reply
Uroš Grum
Reply to Arindam Giri 5 years ago
Thank you for reply, the code is corect, i just changed that when i was trying to
get rid of error and then i forgot to change that back … its not the problem
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
0 Reply
Arindam Giri
Reply to Uroš Grum 5 years ago
Maybe. But make sure you have the latest LibreO ce build and updates
are applied as well. Glad to know it worked!
0 Reply
Ricardo Gunawan
6 years ago
0 Reply
Arindam Giri
Reply to Ricardo Gunawan 6 years ago
I am really not sure why you get that error, I didn’t get. Did you execute the
StartDialog() function? This working example tested in Ubuntu/Linux only. It seems
you are using Windows which may cause this issue. Why don’t you try the alternate
method of creating the dialog as mentioned in the article also below. Keep me
posted.
DialogLibraries.LoadLibrary(“Standard”)
oDialog1 = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
becouse at the time i had de ned it as Dialog … here is my entire code :
Sub StartDialogA()
DialogLibraries.LoadLibrary(“Standard”)
oDialog = CreateUnoDialog(DialogLibraries.Standard.TesniDialog)
oDialog.Execute()
End Sub
Sub ReadDialogA()
Dim cellValue
oT1 = oDialog.GetControl(“TextField1”)
cellValue = ThisComponent.Sheets(0).getCellByPosition(0,0)
oT1.Text = “This”
End Sub
0 Reply
Uroš Grum
Reply to Arindam Giri 5 years ago
I have no clue why …. but suddenly it started to work … iddnt change anny code
….. the libre o ce crashes a lot and even crashes every single time i close the
program , maybe becouse of windows ?
ah well at least now works , thanks 🙂
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
oDialog1.Execute()
0 Reply
Ricardo Gunawan
Reply to Arindam Giri 6 years ago
0 Reply
Hüseyin
Reply to Ricardo Gunawan 4 years ago
Hi;
I have done to show diaglog page on Calc. Please look at below code to help your
mind.
DialogLibraries.LoadLibrary(“VBAProject”)
oDialog1 = CreateUnoDialog(DialogLibraries.VBAProject.Dialog1)
oDialog1.Execute()
0 Reply
Arindam Giri
Reply to Hüseyin 4 years ago
0 Reply
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Facebook Twitter
Instagram YouTube
Fresh Posts
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Robin Hahn
6 years ago
Good start, indeed. I’m glad someone is doing this. BTW, the process creating an object
out of scope, then instantiating and the reading reminds me a bit of Gambas. Going to
have a look at your other tutorials. Then, I’m going to try and start converting some of
my VBA stu .
0 Reply
Arindam Giri
Reply to Robin Hahn 6 years ago
0 Reply
Christoph S
Reply to Arindam Giri 6 years ago
Thanks a lot for this great tutorials, this is exactly what I was searching for!
0 Reply
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
DebugPoint.com is a fastest growing leading technology portal covering So ware,
Operating System, Application, Linux, Ubuntu, Fedora, Windows, Programming,
LibreO ce, Themes, and hardware. We love open-source so ware and on a
mission to raise awareness.
This site serves Ads by a third party that uses cookies and serve ads based on user
browsing patterns.
Ideas and opinions expressed here are my own, and don’t necessarily re ect those
of any other people or organizations.
Categories
Select Category
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
© 2 0 2 1 DE BU G P OI N T.C OM
TOP
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD