Schedule VBA macros on shared Excel File to run Daily? - excel

I have a VBA macro that loads data into the workbook from the database. Currently we share these workbooks with others using Sharepoint, but I want to see how to best schedule the VBA macro once a day for a handful of workbooks, so that the macro runs in each workbook and saves (refreshes) on the shared site.
Is there a way to do this? Perhaps using "office scripts", or OneDrive even?

Related

Excel office script, Worksheets to Workbook

I am trying to figure out ways to make worksheets into workbooks within Sharepoint library.
I have done with VBA to make multiple worksheets into workbooks within desktop.
Is there a method to do this through office script, or power automate?
And also make it user-friendly?
Thank you in an advance.

Personal Macro Workbook Vs Add-In

I am new to VBA and I am trying to determine when to use the Excel Personal Macro Workbook Vs Excel Add-Ins. I am using Office 365 Subscription (up to date) on a single Win10Pro PC.
My understanding is that if one wanted to write a Sub or Function once, and yet have access to it in all open workbooks on the same machine (which is fine for my code), then one could either place the code in the Excel Personal Macro Workbook OR create an Excel Add-In.
Some sites suggest this is simply a matter of preference. Is that indeed the consensus or is there a general set of guidelines for deciding when to utilize one method over the other?

Opening Excel workbook containing macros (.xlsm) using ADO and getting macros to run

I've been using ADO to process many Excel .xls and .xlsx workbooks without any problems. Recently I tried to process a .xlsm workbook to load to an Access database. The workbook contains several macros that are run every time a user opens a desktop version of Excel. The macros update "yesterdays" data with "todays" data. Unfortunately when I read the workbook programmatically ADO is returning "yesterdays" data. This means to me that the macros are not running when I open the workbook with ADO. Any suggestions. Hope I don't need to rewrite the code to open an instance of Excel to handle the workbook.
ADO accesses only the data saved in the workbook. Nothing vba (or any other) code does dynamically when the workbook is opened in Excel is available. Excel macros can only run when the workbook is open in the application interface.
Either your process needs to duplicate what the macro(s) are doing in order to update the sheet data or, yes, indeed, you need to first open the workbook in the Excel environment and execute the macros, then SAVE the changes to the workbook.

Saving VBA code as a separate file in Excel

I have a very complex Excel workbook, with an awful lot of VBA code and macros in it. For version control purposes, I'd really like to be able to save the code as separate files to the workbook proper - to split it off into modules. Is this a thing that's remotely possible?
You should also look into Add-ins (.xlam). These allow your modules/class modules to be referenced in other workbooks. If you deploy a tool to a workgroup then realize that you need to change a macro you can update the .xlam and it gets pushed to all workbooks that reference it.

Can you refer to an external macro with excel?

I have a reasonably complex macro that I need to run on multiple different excel sheets, this macro is updated periodically and whenever a change is made its necessary to change it in each individual excel sheet. is there a way to get each excel document to refer to the one macro?
for example if i had a hierarchy like this:
DOCUMENTS:
-xlsheet1.xls
-xlsheet3.xls
-xlsheet2.xls
MACROS:
-macro1.bas
where there was a button in each sheet that ran macro1 when clicked.
I would recommend either moving that macro to your personal file or create an Add-In
Working with Personal File
Topic: Create and save all your macros in a single workbook
Link: https://support.microsoft.com/en-us/office/create-and-save-all-your-macros-in-a-single-workbook-66c97ab3-11c2-44db-b021-ae005a9bc790
Quote from the above link:
When you first create a macro in a workbook, it works only in that workbook. But what if you want to use the macro in other workbooks? To make your macros available every time you open Excel, you can create them in a workbook called Personal.xlsb. That’s a hidden workbook stored on your computer, which opens in the background every time you open Excel.
Creating an Add-In
Topic: Creating Excel Add-ins
Link: http://www.ozgrid.com/VBA/excel-add-in-create.htm
Quote from the above link:
I am often asked by users 'what is the best way to distribute their macros?' My answer, is without doubt via an Excel Add-in. After all, this is what Add-ins are for. For those that are not sure what an Excel add-in is, it's is nothing more than an Excel Workbook that has been saved as an Add-in, File>Save as \ Microsoft Excel Add-in (*.xla). Once saved and re-opened the Workbook will be hidden and can only be seen in the "Project Explorer" via the Visual Basic Editor. It is NOT hidden in the same way as the Personal.xls as this can be seen (and made visible) via Windows>Unhide.
The Personal file is good for having a macro across any number of workbooks on a single computer. In a networked environment with multiple users, you could simulate the Personal file by having a single workbook with your macros in it and coding all other workbooks to open and hide this workbook when they start up.

Resources