How can multiple users run macros on a shared excel file? - vba

I have an excel file on shared location where multiple users (4 in this case) are accessing the file at the same time.
This file has a “Master data” tab where all the base data is there and then there are 4 identical tabs (one for each user).
Each user tab has a set of filters using which the user will be able to extract relevant data based on the filters selected and can add or edit the rows. Once the user is done editing/adding rows, user will submit the data which will get updated/appended in the master data tab.
Users can select same or different options in the filters. I am facing errors when multiple users click on the submit button (macro) at the same time.
How can I resolve this?

Like some comments say, Excel is not designed for this...
But if you want to use Excel, i would recommend something like this:
Every time someone writes in the master data, you have to "lock" the master data tab. Just put a boolean in a cell, set it to true while you are writing and back to false as soon as you finished altering the master data tab.
Now, if someone wants to change values in the master data tab at the same time, check if the boolean is set to true. If yes, then you have to wait, if not, you can write the data.

Adding to Manuel Allenspach's response, my suggestion is to create a queue.
Queue should have a spot for user processing and other spots for users waiting.
Than, before running code, you should include a check to make sure no two users have their macros updating database at same time.

Related

How to make records read-only once entered in query?

I have a form that a user will input data into, which will then send the added record to the backend of the database (I split the database so that the frontend is accessible to users while the backend is hidden). The frontend also includes a query with no filters, so that it will full portray the backend. This way, users can either input data via the form one record at a time, or add multiple records to the query (and therefore the backend) by copy/pasting from an excel sheet with a specified format (so that the data will be pasted in the same order as the fields of the query).
I want the user to not be able to edit the data/record once it is submitted, but I still want them to be able to view it in the query and/or paste multiple records in the "(New)" record row. Is there a way to make all entered records "read only" per se, but still have the ability to enter new data (i.e. make user unable to edit previous records, but be able to add new records)?
I used this forum as a reference, but the only solution I've come up with was to make the Recordset Type "Snapshot", which does all that I want, except it disables the ability to add a new record.
https://answers.microsoft.com/en-us/msoffice/forum/all/lock-the-entire-record-once-certain-textboxes-have/24f53c0a-2435-48b2-bf91-6713ff8b60ee
I've searched far and wide, but unfortunately haven't come up with anything. Any help would be greatly appreciated. Thank you!

How do I prevent a process from running twice if 2 different users run it at the same time in VBA?

I have a front-end form that fetches data from a back-end table. The front-end has multiple users and they use the back-end table simultaneously. The user uses a form to generate reports. Let's say if a user click the "view" button, the background process will insert data to a table and it will show the result.
However, my problem is if 2 different users from different locations click the "view" button from their end machine at the same time, the process on the back-end table runs twice and it duplicates the data.
I know we can delete duplicate data from the table itself but what I'm trying to do is if there's a way to stop one process if there's already a same process running.
I have found a scenario similar to my problem but it is only caused by clicking the button twice.
Here's the link for the similar problem.
I hope someone could help me out. It's my firs time to use VBA and I have no previous knowledge/experience with it.
I was not able to prevent a process for running twice but we were able to find a workaround for my concern by assigning a compound index to the table. It no longer accepts duplicates regardless of the process running multiple times simultaneously.

Excel data validation list from closed worksheet

I have two Excel 2016 worksheets in the same folder. One is shipment form and the other master database for shipment history. This file also holds the list of "active customers", which obviously changes over time.
When user is creating a new shipment from the shipment form template, I want the customer to be selected from a drop-down list rather than filled in manually. While I'm able to set up standard data validation for a cell, the problem is that the list is maintained in a different Excel file (which, as stated, is in the same folder).
I was also able to set up name reference and have the list from the other spreadsheet available, however I still have one major usability obstacle - it only works when the user has opened the other file, I want to avoid that and just have the user work with shipment form template.
I.e. I'm looking for Excel to fetch the data validation list from another file without forcing the user to keep it open. What are my chances here?
Thanks!
You can use Power Query to get the data from the other file, even if it is closed. Power Query can get the list into the current spreadsheet and you can build the data validation on the Power Query result. You can configure the query to be refreshed when the file is opened, or the user can refresh it manually.

Can I update data in Essbase using Excel add-In/smart view

Can i insert new data/update the existing data into Essbase using Excel add-In/Smart view like I update the data into Palo Multidimentional database?
regards,
Sri.
Yes. This is what Lock & Send is used for. After you have drilled to an intersection that you would to update/load/change data in, you enter it directly in within Excel. Then perform a Lock operation using the add-in or SmartView. This tells Essbase that you would like to update data that is currently being shown on your spreadsheet. Then perform a Send operation. This will upload all of the data on your sheet back to the database, assuming that you have access to change that data (if you are a read-only user or don't have sufficient filter access, for example, then you can't change the data). Note that all of the data in the spreadsheet will be sent up -- so it is useful to navigate to the smallest possible subset of data that you would like to change.
After sending the data, it will automatically be unlocked. Then just retrieve the sheet to verify that the data you uploaded did in fact upload. If you are trying to upload to members that are dynamic calc, for example, then it won't work. Also note that typically data is loaded such that every intersection point is a Level-0 member, if not then it is possible that a subsequent aggregation/calc in the database might erase the data you just uploaded.

Google app script: getting data from spreadsheets without having viewing rights (not installable trigger)

The problem is that I have various spreadsheets (a) for which only one person has viewing and editing permissions, still other persons need some data from those spreadsheets (a) for their spreadsheets (b), they also need to be able to get an updated version of the data from the spreadsheets (a)
I created now a workaround using installable triggers with an on edit function (they have to change a specific field in the spreadsheet) to update the data, but the persons want to have a button/drawing which they can click or a menu entry to get the updated data from the spreadsheets (a).
From my perspective to combine an installable trigger with a button/drawing/menu entry is a dead end. Therefore my question is, if there is any other possibility to grant access to data from spreadsheets without giving viewing or editing rights to the documents where the data comes from...
Would be great if anybody would have an idea, thanks in advance
There are some limits on the Triggers that are used in a spreadsheet that you are going to run into. Check out this for details. Essentially, and onEdit trigger cannot access/modify another spreadsheet as They cannot access any services that require authentication as that user.
To update another spreadsheet outside of the current spreadsheet, I've simply installed a function and a menu item to trigger it. (Is this the dead end you speak of?) It does depend on the user to update the group, but that has been a benefit for my secure data as it requires the knowledge of the key holder to allow others the information. This is A to B, which is possible but B has to have edit access to A's spreadsheet.
No, B cannot get information from A unless they have access to it, as least as viewer. You cannot grant viewing privileges to individual cells, which is essentially what you want to do.
Without that ability, the solution is more in structuring the flow of the data. In one senerio where a user proved they can't be trusted to update the team regularly, I've create myself as 0. I have permissions to A and B. I run the function from 0 to access A and to update B, which also sends them an email, so all know when the last update has happened. Why don't I just use A spreadsheet to run the function, because from 0 I can access it and write it to B without ever seeing the data. It's a veil of ignorance. I never actually open A and 0 remains empty.
Best I could do.
I'm facing a similar problem.
I think that i found a workaround but no guarantee.
I used the importrange function which i intend to control via script.
I have tried the flush function and found it is a good trigger to force the importrange to work, which I added to a Menu (just in case).
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Refresh", functionName: "SheetFlush"});
ss.addMenu("Menu", menuEntries);
}
function SheetFlush() {
SpreadsheetApp.flush();
}
Now, as i don't want the B user to know the A SS unique address.
(when looking to the importrange function)
I am protecting and hiding the sheet with the importrange function in the B SS. And Im using an extra internal refernce in B SS for the hidden sheet.
I might have an answer for your anomaly.
My application client are people from my googleapp workgroup, they don't have permission
to view the files, but they are not a complete strangers.
I think that the following might work.
A file is the muster file with the code.
B file has importrange() function from A with a sharing permission.
And C file has importrange() from B with a sharing permmsion of B file.
the small twist is that B file has a linked sheet which is hide and protected.
I have check this, and if you are not the owner you will be able to unhide it.
In practice, my filling is that you can pull a similar trick with 2 SpreadSheets,
the third one is for extra safety.