[Solved] A Save and Refresh Range Macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
PickmansModel
Posts: 12
Joined: Tue Jul 24, 2012 6:36 am

[Solved] A Save and Refresh Range Macro

Post by PickmansModel »

Just spent 2 hours on the forum looking for this ...
Is there a way to write a macro to "save" the spreadsheet and then "refresh range" so after I update my data, I can just click the button and have the range show as updated?
Last edited by PickmansModel on Sun Jul 29, 2012 7:46 pm, edited 1 time in total.
OpenOffice 3.3.0 on Windows 7
patel
Posts: 36
Joined: Tue Jun 19, 2012 2:48 pm

Re: A Save and Refresh Range Macro

Post by patel »

can you explain better and attach a sample ?
OpenOffice 4.1 on Windows 10
LibreOffice 5.2 on Windows 10
PickmansModel
Posts: 12
Joined: Tue Jul 24, 2012 6:36 am

Re: A Save and Refresh Range Macro

Post by PickmansModel »

So I have a spreadsheet/database set up to get selected (those rows with an "x" in the prepared and known columns) information from sheet1 and put it on sheet2... that works fine.

It works fine, but when I change the data on sheet1 (like if I "select" different or more rows) I need to save the spreadsheet (CTRL+S) and then select my range of data on sheet2 and then Data>Refresh Range.

I know you can make buttons using Form Controls and assign that button a macro. I'd like to write a macro that saves (CTRL+S) and then Refresh Range, so when I update my data on sheet1, all I need to do I click the button to update sheet2.

Savvy?
Attachments
ExampleDB.odb
(2.74 KiB) Downloaded 248 times
Example.ods
(8.41 KiB) Downloaded 388 times
OpenOffice 3.3.0 on Windows 7
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: A Save and Refresh Range Macro

Post by FJCC »

I think this macro will do the job. ThisComponent refers to the document that calls the macro

Code: Select all

ThisComponent.store()
oRange = ThisComponent.DatabaseRanges.getByName("Import1")
oRange.refresh()
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
PickmansModel
Posts: 12
Joined: Tue Jul 24, 2012 6:36 am

Re: A Save and Refresh Range Macro

Post by PickmansModel »

FJCC wrote:I think this macro will do the job. ThisComponent refers to the document that calls the macro

Code: Select all

ThisComponent.store()
oRange = ThisComponent.DatabaseRanges.getByName("Import1")
oRange.refresh()
Nothing happened ... I copied your code then Tools>Macros>Organize Macros>Basic>New
Then I pasted your code between Sub Main and End Sub... Then I added some "X"s on sheet1 and ran the macro. My range did not refresh. Then I saved first, and ran the macro again... still nothing.
OpenOffice 3.3.0 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: A Save and Refresh Range Macro

Post by Villeroy »

Works for me. Works for me. I stored the macro in the document so ThisComponent always refers to the intended document.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
PickmansModel
Posts: 12
Joined: Tue Jul 24, 2012 6:36 am

Re: A Save and Refresh Range Macro

Post by PickmansModel »

I'm a moron ... I had the Macro Security set too high. Works perfectly. Thanks guys!!!
OpenOffice 3.3.0 on Windows 7
Post Reply