Macro to take base data from DataSource to to Calc

Good Morning,
Here is what I am doing manually:

This moves data from Base to Calc very well. However is there a way to accomplish this exact task (including filter) through macro? Thank you very much for your help.

As I can refresh the data from this connection I never tried. But as a first step: What shall your macro do?

  • Create the same connection
    or
  • Open the database and copy data “by script” from database to sheet, without creating a connection for later refresh.
  • You need an additional “filter” on the sheet or is the selected query your filter?

Good Morning,
It should use the second option, and the filter should be on the query.

Thank you.

So lets say it is possible. Some years ago I adapted a macro from the Handbook for Base (german Version mostly by Robert Grosskopf) to sync between two databases for my needs. I have to check, if the english Version contains the same macros. The version seems to be older at tdf: Base Guides | LibreOffice Documentation - LibreOffice User Guides
.
Actually the german page on guides/handbooks seems to be completele different…
Handbücher | LibreOffice - Deutschsprachiges Projekt - Freie Office Suite

I will check. Thank you.

Hello,
You do not need much of a macro if you set the Query to a database range. Then it is a just a couple of lines of code to refresh the range.
.
See Calc macro failing to update sheet data from Base query . It uses the data (via macro) to update a chart, but this you can ignore.

Well I am learning much. I will check this as well.

This looks like a good solution which I might use later. I have decided that manually is good enough for now. Thank you.