Unable to determine why workbook gets marked as read only when opening another workbook via VBA - excel

Background: I can't seem to find an answer for the blunder I've found myself in. I'm working on a dashboard of sorts for our organization that pulls data from different workbooks in different locations. Different people have different permissions within folders in our company. We're trying to prevent having to change permissions. I was also trying to make it easy as possible for employees by moving the necessary supporting files I pull from to my folder where the dashboard is housed that includes a folder with the supporting files. Since this folder has no restricted access, I added passwords to the whole workbook of each supporting file. I created workbooks in the original locations of where these supporting files used to reside with the hopes that would hopefully allow anyone with access in that folder to use this new file as a backdoor/shortcut of sorts. The goal was to keep people's files where they wanted them and allow them to click it then it takes them to my support file and enter the password for them. Which leads me to the problem...
Problem: When I open the "backdoor" file, everything runs normally and the support file opens up with read and write privileges. However when someone else opens the backdoor file, the support file opens as read only. While I don't have any code yet to determine if someone is in the file (I'll cross that road if my problem is resolvable), I've ensured nobody was in the support or backdoor file when another user attempted to use it.
Sub Workbook_Open()
'I didn't have the next statement orginally. Added it in hopes it'd resolve the issue.
'Tried to move it under the workbooks.open command, too, but to no avail.
SetAttr "M:\Report Writing\Supporting Files\TMR 2017 - Team ABC's SF.xlsm", vbNormal
Workbooks.Open "M:\Report Writing\Supporting Files\TMR 2017 - Team ABC's SF.xlsm", , False, , "XXX"
Workbooks("TMR 2017 - Team ABC's.xlsm").Close
End Sub
I also didn't originally have the "False" in the open.workbooks command but tried to add it in hopes of resolving my dilemma. Any hope is GREATLY appreciated as my whole dashboard is relying on this and we were supposed to deploy today.

It has nothing to do with the VBA code. It is the file itself. On a shared network, depending on how it was set up, when a new file is created everyone can read it, but only the creator is marked as the only one allowed to make changes. If someone Saves the file with another name you wont be able to edit it. You created the file, you can make changes to it.
There is a way to change this. Right click on the file, properties, security, Edit Button, There are some listed users in there but just find the one that says Drive\Users or Authenticated Users, or both, and edit that to provide modify access. This will allow everyone to edit the file.

Related

How to prevent user from saving changes to the master excel file?

I have a fair understanding of basic to intermediate VBA coding - here's the predicament I am having at work - I am responsible for maintaining this master excel file that consists of 35 tabs and macros and event procedures etc. - this file is used by the other team (more than 10 people) as the primary tool for carrying out their daily tasks - as the author i always keep an original copy of this file as a backup for any contingent event, and I put a copy of the file in the team folder for the team to use.
However, it sometimes happens that some of the team members would open this file in the team folder and make changes (they are told not to) as normal practice and accidentally save the changes withtout realising it - now that potentially creates an issue for the next user (good user) who would make a copy of this file and save it to their own folder and continute to work on with it (good practice) but they did not realise there has been data left in the workbook from the previous user - this kind of incident could create a disatrous consequency if it's left unnoticed.
I am trying to think up a way or series of codes that can resovle the issue - i just do not know which way to begin with - I was thinking of using SheetChange or Open (eg upon detecting any change then save as a new file in a different location) event - with that i ran into another issu- how i do ensure the subject event will not intervene other events that already exist in the workbook in the subsequential workbook?
any suggestion on structuring the code to accommedate this situation?
many thanks in advance
#VBA #event #savechange
as described in above
I would keep the master copy well hidden from them.
Then, consider putting passwords on sheets they MUST not change.
Or, consider sub-master files for the detail that each team can change and then your master file can link to those sub-files to get the latest data.
I had a project to manage that had 6 team members. Gave them each their own file and linked to their data. Also passworded the functions so they could not change or delete them.
Save the file as an Excel Macro-Enabled Template (.xltm) file.
This way, on double-clicking the file (as you would to open any other file), it creates a new file and will not automatically overwrite the old file when saving.
Instead of taking copies of the file, your users simply have to 'open' the file then later save as whatever they need to.

VBA: Set permission to read Excel file to whole organization

So, I've run into a VBA problem. Due to IT policies I can't control read/write access to my Excel files on folder level, but have to do it for each individual file. I have a folder with 15 files, that everyone having access to the folder can access and write in. On a certain date I want to lock these files down, so that only a specific group can write, but the rest can still read.
I'm aware it's realtively easy to do this manually (File->Info->Protect Workbook->Restrict Access), but since I already run a macro for other reasons when we want the files locked down, I'd like for it to do this part too. This is where I run into my problem:
I've figured out how to set the permission for a specific user, using this code
Sub set_access()
Dim UserPerm As Office.UserPermission
Workbooks("workbook name").Activate
Set UserPerm = ActiveWorkbook.Permission.Add("name#company", msoPermissionFullControl)
I can loop through this for each person I want to have writing/full access, no problem. There's like fifteen of us and I know who we are.
The thing is I also want everyone in my organization to retain their reading rights. This has it's own button if I do it manually (in the Permission menu that is accessed as mentioned above), but I can't understand how to trigger that setting via vba. I've tried to record a macro of me doing it manually, to see the code, but nothing is recorded. I've also read just about everthing I could find online like four or five times, and what I need simply doesn't seem to be covered.
Does anyone know if this is poosible? Or if it isn't; can I reach the same results some other way?
tldr: I can set permission by individual, but in addition to this I want to give a general read-only access to my Excel files for anyone in my organization. Can this be done with vba? If so; how?
I had the same problem and was looking into it. After all, by using "Everyone" instead of an email address, I was able to set permissions for everyone in my organization. try it.

Access control for Excel files on FILR (Novell)

We have just started using Filr as our file sharing platform, in short we have a seperate excel file for each of our shipments that we export and we have different users accessing these files although editing should never happen concurrently.
I have no formal IT background, I am an accountant and I know the basics. I have over the last year started teaching myself VBA using trial and errors from what I find on platforms like these so I apologise for any ignorance :)
The problem is that it seems Filr allows any excel files to be edited by multiple users, without any warning when opening the file and without the sharing capabilities being activated within excel. This is causing conflicting copies being created and confusion as to which is the correct file. I have tried to address this with the IT department (from our marketing company) managing Filr and am not getting any real assistance to address the problem.
So I decided to explore using VBA to warn or open as read only if a file is already open by another user and I have tried to no avail using similar posts to test if the file is open.
I have gotten to the point that it recognises that the current person opening the file, has the file open, which is pretty obvious. But get no further for it to recognise that another user already has the same file open.
Am I chasing a unicorn? Is this perhaps only controllable by Filr setup / settings? Or does anyone have any magical insight to help?
I hope I have posted my problem appropriately :)
Here is my code, so it detects me as 1 user, but when my colleague opens the file after me it still only detects the user count as 1 (not 2 for both of us):
Sub Workbook_Open()
Users = ActiveWorkbook.UserStatus
If UBound(Users) = 1 Then
MsgBox "File not in use"
Else
MsgBox "File already open"
End If
End Sub

User option in Access to select unique filepath for Excel source data

I am working off of a great solution created by #MattHall from 2011 to a question that I also shared about importing a dynamic range from Excel into Access.
Specific to that--though in general for future VBA's--my question is whether there is an additional way to be able to point to the Excel source file if it is moved without having to go into the VBA editor every time?
For my specific needs, I am trying to work on these Access and Excel files with others through a shared BOX that has a different file path for whoever is working on it.
USER 1 may be: C:\Users\USER1\Box Sync\filename.xlsx
USER 2 may be: C:\Users\USER2\Box Sync\filename.xlsx
...and so forth for any other users. I am curious how we can all work off this when the file path used in the VBA created and used by USER1 is not accessible by USER2? Could there be some code that allows for the every user to locate the file each time through their own filepath?
It would be a pain to do that but I also do not know a better option as we are not working off a shared server and this is unfortunately limited to Box share at the moment.
EDIT: If anyone could also suggest how to integrate their recommendation into the 'Dynamic Range' code in solution from #MattHall in the linked Stackoverflow, that would particularly helpful to my request.

Add ActiveX component to Excel Spreadsheet [duplicate]

I have some Excel worksheets that use ActiveX checkboxes to control certain activity. They worked recently but today started to give errors. I was alerted to this by a colleague, but it was still working on my computer. I checked his version of Excel against mine and his was newer. I noticed there were new Windows updates, so I did the update. After I applied pending updates, it now no longer works on my computer. I cannot check the ActiveX checkboxes any longer, and, as a part of trying to debug, it appears I cannot even add an ActiveX control to any worksheet, even a new worksheet, any more. I get an error dialog that says, "Cannot insert object." (I can still add form controls, just not ActiveX.) Anyone else experiencing this after a recent update? Any suggestions?
Thanks,
Mike
From other forums, I have learned that it is due to the MS Update and that a good fix is to simply delete the file MSForms.exd from any Temp subfolder in the user's profile. For instance:
C:\Users\[user.name]\AppData\Local\Temp\Excel8.0\MSForms.exd
C:\Users\[user.name]\AppData\Local\Temp\VBE\MSForms.exd
C:\Users\[user.name]\AppData\Local\Temp\Word8.0\MSForms.exd
Of course the application (Excel, Word...) must be closed in order to delete this file.
Here is the best answer that I have found on the Microsoft Excel Support Team Blog
For some users, Forms Controls (FM20.dll) are no longer working as
expected after installing December 2014 updates. Issues are
experienced at times such as when they open files with existing VBA
projects using forms controls, try to insert a forms control in to a
new worksheet or run third party software that may use these
components.
You may received errors such as:
"Cannot insert object" "Object library invalid or contains references
to object definitions that could not be found"
Additionally, you may be unable to use or change properties of an
ActiveX control on a worksheet or receive an error when trying to
refer to an ActiveX control as a member of a worksheet via code.
Steps to follow after the update:
To resolve this issue, you must delete the cached versions of the
control type libraries (extender files) on the client computer. To do
this, you must search your hard disk for files that have the ".exd"
file name extension and delete all the .exd files that you find. These
.exd files will be re-created automatically when you use the new
controls the next time that you use VBA. These extender files will be
under the user's profile and may also be in other locations, such as
the following:
%appdata%\Microsoft\forms
%temp%\Excel8.0
%temp%\VBE
Scripting solution:
Because this problem may affect more than one machine, it is also
possible to create a scripting solution to delete the EXD files and
run the script as part of the logon process using a policy. The script
you would need should contain the following lines and would need to be
run for each USER as the .exd files are USER specific.
del %temp%\vbe\*.exd
del %temp%\excel8.0\*.exd
del %appdata%\microsoft\forms\*.exd
del %appdata%\microsoft\local\*.exd
del %appdata%\Roaming\microsoft\forms\*.exd
del %temp%\word8.0\*.exd
del %temp%\PPT11.0\*.exd
Additional step:
If the steps above do not resolve your issue, another step that can be
tested (see warning below):
On a fully updated machine and after removing the .exd files, open the file in Excel with edit permissions.
Open Visual Basic for Applications > modify the project by adding a comment or edit of some kind to any code module > Debug > Compile
VBAProject.
Save and reopen the file. Test for resolution. If resolved, provide this updated project to additional users.
Warning: If this step resolves your issue, be aware that after deploying this updated project to the other users, these users will
also need to have the updates applied on their systems and .exd files
removed as well.
If this does not resolve your issue, it may be a different issue and
further troubleshooting may be necessary.
Microsoft is currently working on this issue. Watch the blog for
updates.
Source
It was KB2553154. Microsoft needs to release a fix. As a developer of Excel applications we can't go to all our clients computers and delete files off them. We are getting blamed for something Microsoft caused.
I'm an Excel developer, and I definitely felt the pain when this happened. Fortunately, I was able to find a workaround by renaming the MSForms.exd files in VBA even when Excel is running, which also can fix the issue. Excel developers who need to distribute their spreadsheets can add the following VBA code to their spreadsheets to make them immune to the MS update.
Place this code in any module.
Public Sub RenameMSFormsFiles()
Const tempFileName As String = "MSForms - Copy.exd"
Const msFormsFileName As String = "MSForms.exd"
On Error Resume Next
'Try to rename the C:\Users\[user.name]\AppData\Local\Temp\Excel8.0\MSForms.exd file
RenameFile Environ("TEMP") & "\Excel8.0\" & msFormsFileName, Environ("TEMP") & "\Excel8.0\" & tempFileName
'Try to rename the C:\Users\[user.name]\AppData\Local\Temp\VBE\MSForms.exd file
RenameFile Environ("TEMP") & "\VBE\" & msFormsFileName, Environ("TEMP") & "\VBE\" & tempFileName
End Sub
Private Sub RenameFile(fromFilePath As String, toFilePath As String)
If CheckFileExist(fromFilePath) Then
DeleteFile toFilePath
Name fromFilePath As toFilePath
End If
End Sub
Private Function CheckFileExist(path As String) As Boolean
CheckFileExist = (Dir(path) <> "")
End Function
Private Sub DeleteFile(path As String)
If CheckFileExist(path) Then
SetAttr path, vbNormal
Kill path
End If
End Sub
The RenameMSFormsFiles subroutine tries to rename the MSForms.exd files in the C:\Users\[user.name]\AppData\Local\Temp\Excel8.0\ and C:\Users\[user.name]\AppData\Local\Temp\VBE\ folders to MSForms - Copy.exd.
Then call the RenameMSFormsFiles subroutine at the very beginning of the Workbook_Open event.
Private Sub Workbook_Open()
RenameMSFormsFiles
End Sub
The spreadsheet will try to rename the MSForms.exd files when it opens. Obviously, this is not a perfect fix:
The affected user will still experience the ActiveX control errors when running the VBA code the very first time opening the spreadsheet. Only after executing the VBA code once and restarting Excel, the issue is fixed. Normally when a user encounters a broken spreadsheet, the knee-jerk reaction is to close Excel and try to open the spreadsheet again. :)
The MSForms.exd files are renamed every time the spreadsheet opens, even when there's no issue with the MSForms.exd files. But the spreadsheet will work just fine.
At least for now, Excel developers can continue to distribute their work with this workaround until Microsoft releases a fix.
I've posted this solution here.
With Windows 8.1 I couldn't find any .exd files using windows search. On the other hand, a cmd command dir *.exd /S found the one file on my system.
Advice in KB and above didn't work for me. I discovered that if one Excel 2007 user (with or without the security update; not sure of exact circumstances that cause this) saves the file, the original error returns.
I discovered that the fastest way to repair the file again is to delete all the VBA code. Save. Then replace the VBA code (copy/paste). Save. Before attempting this, I delete the .EXD files first, because otherwise I get an error on open.
In my case, I cannot upgrade/update all users of my Excel file in various locations. Since the problem comes back after some users save the Excel file, I am going to have to replace the ActiveX control with something else.
The best source of information and updates on this issue I could find is in the TechNet Blogs » The Microsoft Excel Support Team Blog (as mentioned):
Form Controls stop working after December 2014 Updates (Updated March 10, 2015)
On March 2015 a hotfix was released in addition to the automated fix-it and manual instructions, and it's available on Windows Update as well.
The latest update and fix from Microsoft:
3025036 "Cannot insert object" error in an ActiveX custom Office solution after you install the MS14-082 security update
STATUS: Update March 10, 2015:
Hotfixes for this issue have been released in the March 2015 Updates for Office 2007, 2010 & 2013.
General info about the problem:
For some users, Form Controls (FM20.dll) are no longer working as expected after installing MS14-082 Microsoft Office Security Updates for December 2014. Issues are experienced at times such as when they open files with existing VBA projects using forms controls, try to insert a forms control in to a new worksheet or run third party software that may use these components.
https://technet.microsoft.com/en-us/library/security/ms14-082.aspx
You may receive errors such as:
"Cannot insert object"; "Object library invalid or contains references to object definitions that could not be found"; "The program used to create this object is Forms. That program is either not installed on your computer or it is not responding. To edit this object, install Forms or ensure that any dialog boxes in Forms are closed." [...]
Additionally, you may be unable to use or change properties of an ActiveX control on a worksheet or receive an error when trying to refer to an ActiveX control as a member of a worksheet via code.
Manual and additional solutions:
Scripting solution:
Because this problem may affect more than one machine, it is also possible to create a scripting solution to delete the EXD files and run the script as part of the logon process using a policy. The script you would need should contain the following lines and would need to be run for each USER as the .exd files are USER specific.
del %temp%\vbe\*.exd
del %temp%\excel8.0\*.exd
del %appdata%\microsoft\forms\*.exd
del %appdata%\microsoft\local\*.exd
del %temp%\word8.0\*.exd
del %temp%\PPT11.0\*.exd
Additional step:
If the steps above do not resolve your issue, another step that can be tested (see warning below):
On a fully updated machine and after removing the .exd files, open the file in Excel with edit permissions.
Open Visual Basic for Applications > modify the project by adding a comment or edit of some kind to any code module > Debug > Compile VBAProject.
Save and reopen the file. Test for resolution.
If resolved, provide this updated project to additional users.
Warning: If this step resolves your issue, be aware that after deploying this updated project to the other users, these users will also need to have the updates applied on their systems and .exd files removed as well.
Simplified instructions for end-users. Feel free to copy/paste the following.
Here’s how to fix the problem when it comes up:
Close all your Office programs and files.
Open Windows Explorer and type %TEMP% into the address bar, then press Enter. This will take you into the system temporary folder.
Locate and delete the following folders: Excel8.0, VBE, Word8.0
Now try to use your file again, it shouldn't have any problems.
You might need to wait until the problem occurs in order for this fix to work. Applying it prematurely (before the Windows Update gets installed on your system) won't help.
I did finally find this answer on the official Microsoft KB:
http://support.microsoft.com/kb/3025036/EN-US
No new information here than what we have in previous answers, but at least it acknowledges that Microsoft is aware of the issue.
I know many answers have already been posted for this, but neither one answer independently worked for my site. So here is what worked for me:
Step 1: Uninstall the following updates - KB2920789, KB2920790, KB2920792, KB2920793, KB2984942, KB2596927
Step 2: Hide these updates so they do not get installed on subsequent reboots
Step 3: Delete folder Excel8.0 from C:\Users\<>\AppData\Local\Temp
Step 4: Restart workstatiion (I would also make sure the above mentioned KBs did not inadvertently get applied)
I want to provide an answer that worked as the only thing for me (I realize that I might be the only one ever). I had in one macro that I was calling using the ribbon. It had the following code:
colStore = new Collection
I wasn't aware that it throws an error so I was baffled and tried everything in here. The button just stopped working and I couldn't get it to work. When I noticed the error and corrected it to:
Set colStore = new Collection
It started working again. Absolutely strange if you ask me but maybe it helps someone out there who was as desperate as me.

Resources