Only I am able to save a macro-enabled workbook? - vba

All, I have created a workbook that has some macros in it to import data. The idea is that the file is a master file, and every time you import data with it, it is supposed to place that data on the end of the existing data, and then you save it and move on.
The problem is, I am the only user that can save the workbook. Now, two of the sheets in my workbook I have protected, so that they cannot be edited. I have done this so that nothing can accidentally be removed (buttons, instructions, notes, etc). My users have agreed that this protection is a good thing.
But what I think is happening is our network is making anyone who didn't author this file open it as Read Only, and then they cannot save to it. I first thought maybe if added a save macro (and command button) that it would fix it. No dice.
Next, I had the workbook unprotect, and then re-protect itself when the user clicks the save button. Nope, still opening as Read Only.
I then put code in the Workbook_Open() Sub that changed it from Read Only to Read Write. This caused a box to popup when opening the sheet that said the file was in use by "Another User," and it was locked for editing.
The last thing I tried was adding the other users as Authors to the workbook. And it STILL opens as a Read Only file.
I think this has to do with the network settings here in our office (well, corporate-wide, but anyway). These are policies that cannot be changed. Can anyone help me find a work-around that allows my sheets to be locked for editing, but allows my users to save to my workbook?
You can see here that I have added three other users as Authors of the file (This is the information page of the file as opened by a user.):

So it turns out that the issue was not related at all to the workbook...
When attempting to Save As in the folder where the workbook was located, we found out that the user I was using for the tests simply did not have write permissions to the folder in question. I had write permissions to it based on a previous assignment.
So much frustration over something so simple.

Related

Lock or Freeze VBA Code to Prevent Editing

Is there any way I can lock or freeze the VBE editor to prevent others from accidentally editing the VBA code?
I don't want to lock down the whole workbook where people can run macros but can't see the code.
I want to let others see the code but don't want them accidentally deleting something and break the program (something even I am prone to doing to my code).
Just go to Visual Basic, right click your module, select VBA Project Properties..., under protection tab, you can lock your VBA code with password.
Hope this help. ^^
If you want the code to be visible and executable, then you can't stop people from making changes to it.
You can however, stop them from saving those changes, by opening the workbook as read-only.
You can mark a workbook as read-only in the File Properties from within File Explorer. Or, if your workbook is opened via Automation, then you can specify read-only in the open method.

Way to capture double click to open file?

Is there a way to have an Excel macro to check what file I double clicked on to open.
When I open that file, the Add-Ins installed load first, then the file I clicked on loads. How can I write code inside one of my Add-Ins to check what the filename is that I am trying to open?
I tackled this by using 2 instances of Workbook_Open inside an excel Addin.
When a file is loaded, the addin starts up, and checks to see if there are any active workbooks. If there is none, then we wait a little bit and check again, looped as many times as you deem necessary, or until there is a valid workbook open. This makes sure your computer has time to load up the excel file. Once there is an active workbook, we process it to make sure it is not the workbook of the addin. If it is, then we exit our code. If it isn't then we Do Stuff.
I solved 2 of my questions on this site with the same code that can be found HERE
Note: I left out the parts where I Do Stuff... because really it's there to do anything you want with it. The code in the link just does what the previous paragraph describes.

Macro not responding on different computer

I have a macro which works fine on my computer when I click its button but it does not work on different computers.
All the macros on that excel file are not working when clicking on the button.
However, I have a macro working before saving. That means that when I try to save, another macro works properly. (that macro pop up an input message, but is not relevant now). So it seems that macros are not working only when you call them by a click...
The version of Excel is the same one and I enabled the macro when asked.
It is not a problem of the code because even if I create a new simple macro on that file from the different PC (such as:
msgbox("hello")
) it is still not responding.
I had a problem with that excel file in the past and I had to manually delete all the *.exd extensions in my computer. However once I deleted those extensions, the file worked well.
I believe that the excel file is considered corrupted by other computers and they do not enable the macro. This is just my impression but I cannot get why the macro is working when saving and not working when clicking.
Do you have any idea to solve the problem?
I had issues like that myself both with macros and with Excel workbook doing some really funny stuff (like formulas not calculating properly, or functions not working as expected etc) and I did not find any other solution then copying the content of the file and pasting into a newly created file.
In each case this resolved my problem.
It suggests that my files somehow got corrupted and the only solution was to save the contents and delete the files.
Exporting the .frm and .frx files from VBEditor (Modules and Forms) worked fine for me.
Have you tried this yourself?
This may be too simple a suggestion, but have you checked the security settings in Excel? The other computers may be set to a higher security setting that disables all macros without notifying the user.
https://support.office.com/en-US/Article/Enable-or-disable-macros-in-Office-documents-7b4fdd2e-174f-47e2-9611-9efe4f860b12?ui=en-US

VBA Password Protect Excel Workbook without Save

It is possible to password protect an excel workbook for opening without the use of SaveAs method (without any method to save the file)?
Currently in our application, we use the SaveAs method to save and set the password after a workbook is generated and filled with data. The generation of this workbook takes a while as we use a lot of data and the resulting file is quite big (120MB).
We were searching for some ways to accelerate the workbook generation and we found that the SaveAs method takes around 3 minutes to complete because a lot of formulas needs to be calculated. After a small talk with the users, we realize that everyone make some small changes to the UI of the workbook anyway so then they need to save again and wait for another 3 minutes.
We have decided to suppress the SaveAs method and will be the users responsibility to save the workbook after they finish with their changes. And here is the problem, without the SaveAs I couldn't find a way to protect the file with a password.
I have tried the Workbook.Protect but it seems it only protects the structure and the windows from changes but not the file from opening:
ActiveWorkbook.Protect Password:=cPwd, Structure:=True, Windows:=False
I also found the Workbook.ProtectSharing method but I did not tried because the documentation says that it saves the file.
So, is there any way to set a workbook password without saving the file that will be applied when the user save it manually after his changes?
You can use the Workbook.Password property, which is read/write. The password will be applied the next time the file is saved.

Excel - Keep macros enabled when sheet is saved as new

I have an excel macro-enabled sheet that users open, fill out a list of information (name, date, etc) and click a save button. This creates a new file name based on the information, and saves the file to a network location. The users then continue to work with the sheet.
I forced the users to enable macros (excellent tutorial here: http://datapigtechnologies.com/blog/index.php/forcing-your-clients-to-enable-macros/) and that works well, however once the file name changes, macros are disabled. I assume this due to the fact that it is an untrusted network location. The sheet will be used by many different computers, so I would like to find a vba workaround rather than relying on an excel setting.
Edit: I think I have the answer: As #mehow said based on the link I have posted, I can first run the part of the macro that finds the file name, then lock the workbook all except the start page, then save the workbook as the new name, then hide the start page and show everything else. That way if macros are disabled once the sheet is saved it should force the user to re-enable without compromising the protection. I'll post once I find outwhether it will work.
Edit: It works! Thanks.