I use the following software:
Version 24.2.7.2 (x86_64) Libreoffice
Linux – latest version
I have developed a series of macros (using different modules) using BASIC to play a simple game for my own use. My issue is once I create another Calc spreadsheet for other general uses the macros from my game appear in other spreadsheets. I have used Excel and macros stay in the spreadsheet it was created in.
I have looked and looked but what I can find is:
Below is from a 2013 question.
“You need to save the macro in your document instead of LibreOffice. Then the macro will only be available when you load that document.”
I have also saved the Basic manually, directly from the macro editor. The current folder is “my macros & dialogues”> “Standard” > “Module1”.
I eventually managed to move my macros (there are many of them so a single macro called “main” will not work) into the" My Document"> Standard> Module1 folder. Not a straightforward process, I had to copy and paste. The “Save As” option was grayed out. “My Document” insists on looking in the original location in the My Macros & Dialogues folder. I guess I did not find the correct method to transfer the basic. Is there a way of pointing “My Document” to the correct folder?
From another person’s question on a similar question:
“The basic concepts have not changed much over the years.
At first: Store the macro in the Calc-File, not in your library. Then it is only available, when the file is open.
Further steps may be password-protections for library or table.
Last step: Put the file in a veracrypt-container, so it is only available, when the container is opened…
.
For maximum security however: delete after using…”
I’ve tried but I’m new to Libreoffice and it’s slow going and I don’t understand the solutions. Any specific help would be greatly appreciated.
I thought I should try Ai and this is what it came up with:
Answer
To address your issue of macros appearing in other spreadsheets when you only want them in a specific document, you need to store the macros within the Calc file itself rather than in the global LibreOffice library. Here’s a step-by-step guide to achieve this:
- Open your Calc spreadsheet that contains the game macros.
- Go to Tools > Macros > Organize Macros > LibreOffice Basic.
- In the Macro dialog, expand the “My Macros” tree and select the module containing your game macros.
- Click “Edit” to open the Basic IDE.
- In the Basic IDE, select all the code for your macros (Ctrl+A).
- Copy the selected code (Ctrl+C).
- Close the Basic IDE.
- In the Macro dialog, expand the tree for your current document (it should be listed under “Document”).
- If there’s no module in your document yet, create one by clicking “New Module” and giving it a name.
- Select the newly created (or existing) module in your document and click “Edit”.
- In the Basic IDE for your document, paste the copied code (Ctrl+V).
- Save the document.
Now, your macros are stored within the Calc file itself and won’t appear in other spreadsheets26. To remove the macros from the global library:
- Go back to Tools > Macros > Organize Macros > LibreOffice Basic.
- Expand “My Macros” and select the module containing your game macros.
- Click “Delete” to remove the module from the global library.
Regarding your question about pointing “My Document” to the correct folder, this isn’t necessary. When you store macros in the document itself, they are saved within the .ods file, not in a separate folder6. If you want to organize your macros into different modules within your document:
- Open the Macro dialog (Tools > Macros > Organize Macros > LibreOffice Basic).
- Expand your document in the tree.
- Click “New Module” to create additional modules as needed.
- Organize your macros into these modules as desired.
By following these steps, your game macros will only be available in the specific Calc file you’ve created for your game, similar to how Excel handles document-specific macros26.