excel initialize 'protect/unprotect sheet' with a userform - excel

I have made an Excel file in which operators from a manufacturing company can log malfunctions/failures or anything that stops production. The way an operator logs a malfunction, is by clicking on a button on one sheet, that opens a userform created with VBA in Excel.
The operator fills in all the required fields through dropdown menus (operators' name, team, malfunction type, machine name, etc). When the operator is finished, he or she can press on the save button which will write all the data to another sheet in a standardized way, so it is ready to be used for data visualization.
The problem
Some operators do not use the userform to log a malfunction, but type directly into the data sheet, which contradicts the logging of malfunctions in a standardized way. Simply hiding the sheet, or putting a password on it is not an option, because operators must be able to see all the logged malfunctions by others as well.
Possible solution
I have been thinking and the only solution to solve this, is to make the data-sheet readonly. But the problem that occurs then, is that the userform isn't able to put the data into the sheet as well. So i think the best way to solve this, is to put a readonly on the sheet at all times, but when the userform opens, the sheet is unprotected (so it can save the data on the sheet), and when the userform is closed it will be readonly again. Feel free to ask if you need anything.
Thanks in advance.

The Worksheet.Protect method has an option to only stop the user from changing data on the sheet. set UserInterFaceOnly to True:
Worksheet.Protect Password:="randompass" UserInterfaceOnly:=True
Then the code can change the data but the user can't

Related

Cannot run the macro Listbox4_Change. The macro May not be available in this workbook or all macros disabled

Can anyone please help me with excel issue. I have created a dynamic dashboard in excel using sumifs on data layer and index match functions on presentation layer. I have placed a simple List box form control with no VBA or macro.
My dashboard was working fine, without any issue, but on final step I was just trying to make the List box control float on the sheet with scrolling.
I found a vba code, I opened vba from developer mode, pasted code, but that deleted same.
Since then upon any selection of List box item, it is giving me error “ Cannot run the macro Listbox4_Change. The macro May not be available in this workbook or all macros disabled.”
I have tried pretty much every thing I found on google. Created a macro and deleted, copied one line code in all sheets of vba and deleted, enabled Macro security setting, but nothing really is working .
I am stuck badly.
It sounds like you've added a macro and then removed it, but haven't removed the macro assignment on the list box.
Right-click on the control and choose Assign Macro, delete the Macro name, and hit OK.

Copying data from a dropdown menu to a seperate sheet as a report using VBA

Complete beginner with VBA and I think I'm doing something majorly wrong.
So context;
Creating a user friendly sheet to do checks on items etc. To keep it as simple as possible for other people I've decided to use drop down menus to input the majority of the data and tick boxes to say when the check has been done.
From here I want to add a big old button that will transfer the data from the cells, dropdown menu and tick boxes to another sheet or workbook.
I would also need the sheet or workbook to place the date the checks were done and create a new line with the information. So that I can look at a single sheet and see the wear and tear on the equipment in one form. (layout of this can be sorted out after wards just how to get it to go to a blank line etc.)
And finally to save the document.
drop down information is linked from another sheet within the workbook.
Now I've tried some code to work it out myself and it either doesn't copy the data as the cell is blank (drop down menus) or it just shoots up an error on the VBA page.
Could anyone assist in helping me work this code out? Even if its just the command syntax's that I would need to use.
Thanks in advance
Peter

Having a sheet that contains buttons for macros that run off of selections

Is it possible to use Selection to define data used in a macro button that is in another sheet.
I'm trying to make a template workbook that's first sheet is a bunch of macro buttons. I want to be able to select data in another sheet, click my button sheet, and click my button to run a macro on the data I have selected in the other sheet.
The problem that I'm running into is that sheets seem to have independent selections at the same time. So my macro always runs on the selection from the button sheet instead of the sheet I was on. Any thoughts on how I can make this work? The selection of the data needs to be dynamic, so I can't just say .Cells(1,1).value because it might not be the data I need.
Say there are two types of sheets:
a set of data-sheets
a single button-sheet which controls processing via macros tied to buttons
We code a single global range variable in a standard module. We code selection change event macros in all the data-sheets. Then:
We click on a data-sheet
We select cells on the data-sheet
the event macro on that data-sheet records the selection in the global variable
We click to get on the button-sheet
We click on a button
the button macro retrieves the global range
the button macro determines the sheet associated with the stored range (from the Parent Property) and also the cells on that sheet which we selected
the button macro processes the data
EDIT#1:
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Also just Google: Excel VBA Event Macro
(there are many examples in this forum, for example)
https://msdn.microsoft.com/en-us/VBA/Excel-VBA/articles/workbook-sheetselectionchange-event-excel
In this link is where I need to start. Every time that I change my selection it runs an event where I could maybe grab the cell values and store them in an array that will stay static when I change sheets. If I get it right I'll post it here. 5/31/2018
To Accomplish this I made rng a public variable and stored my selection from sheet2 in it. Then I used a click event in my buttons to to call the macros that I wanted to run on my range. Here are some screenshots of the codes in my modules and in my sheets. This answer is for anyone that finds this in the future.
https://imgur.com/a/DJDaQiM
The Biggest thing to take away from this is that Public Variables in vba only have to be declared once in any of your modules. NOT IN YOUR SHEET CODE. This was the biggest thing that held me back from getting this done. Good luck and contact me with any questions.

Excel - Disabel ability to manually change sheets (but don't hide them)

Apologies if this is a really stupid question but I've not been able to find a solution.
I've got a main page on my Excel workbook with a number of filter options and some buttons linked to vba code. When clicking the button it takes you another tab with a load of data filtered appropritately. There is a button there that removes the filters and takes you back.
This all works fine but what I want to do is stop people being able to manually change sheets but clicking on the tabs at the bottom of the screen. So far the only method I've found is hiding them, but this obviously doesn't work as you then can't see that data.
You can disable the editing of the sheet tab names by turning them off on the excel options as mentioned in the comment above. The downside to this approach is the user won't be able to see what sheet they are on (which I find incredibly frustrating).
The better method in my mind is to set up an event listener for when the user changes the name of the tab. You can then send a pop up box that appears when the user attempts to change the tab name.

preventing Excel app from being emailed

I have employees that use a macro/external data enabled Excel file. One of the worksheets in this file contains proprietary data, that is populated from an external data source ODBC connection. This proprietary worksheet is always hidden from the user, because it just serves as a Vlookup-function data-source
I want to prevent my employees from accidentally emailing this Excel file, because I don’t want the hidden worksheet data to be available to non-employees
Please advise if there is anything I can do prevent the email recipient from being able to view the data that is in the hidden worksheet, if the app is accidentally emailed to them.
Are any of the following ideas feasible?:
Password protecting the hidden worksheet, yet, not preventing the Vlookup function from the other worksheet from functioning?
Imbedding something into the app that resembles a virus, to cause all email servers to block the attachment.
Creating a macro that deletes the data from the hidden worksheet when the app is closed
Imbedding large images into the app to make it too large to email, but yet won’t affect the performance.
Please advise, thank you very much in advance, Nathaniel
In regards to number 3, there is a setting like this in the Connection Properties. It's "Remove Data from the external data range before saving the workbook." I'm not looking at XL 2003, but it's nested under the "Refresh Data When Opening the File" option. As others have said, this isn't foolproof, but it might help meet your requirements.
I don't think you can fundamentally prevent your workbook to be sent around. Password-protecting the sheet would be of little help, as it is fairly easy to bypass. The safest approach to protect your proprietary data from prying eyes would be to not have it in the worksheet itself, retrieve it dynamically by prompting the user for some credentials, and never save it in a worksheet.
You can hide the sheet from the developer tab of excel. To do this, follow the steps below
Open the excel
Press Alt + F11
Here you can see the list of sheets on your excel file
Select the sheet that you want to hide
When you select the sheet you can see the properties of the particular sheet below
Set the visibility property to ‘2 – xlSheetVeryHidden’
Now right click on the sheet and select VBAProject – Project Properties
Navigate to the Protection tab and check ‘Lock project for viewing’
Set a password
Sheets hidden in this way cannot be un hidden unless one has access to the VBA Project (but this is now password protected). The sheet can be seen only if you know the password.

Resources