Excel cell locked when it is not locked - excel

I have experienced the exact same problem as mentioned in this post.
Excel thinking cells are locked when they aren't
I tried to ask for clarification by responding / reviving the thread but it appears this is not the correct protocol. I only came across this post after numerous search string searches and this is the only relevant "hit" I could find.
My spreadsheet is similarly complex and has been running flawlessly through Excel 98, 2003 and 2010. When I use Excel 2013 (and I believe same problem happens with Excel 2016) I find cells which are unprotected (for data entry) become locked following use of a macro button, typically navigating to view a graph and then returning. Properties of the cell confirms the cell is not protected.
Reading the above post and the Microsoft links, I have only a shallow understanding of the problem i.e. SDI / Single Document Interface.
The above referenced post received a solution that was acknowledged as having resolved the issue. Perhaps I did not fully understand but no matter where I placed the code snipped it did not help me.
The code offered was:
Private Sub UserForm_Layout()
Static fSetModal As Boolean
If fSetModal = False Then
fSetModal = True
Me.Hide
Me.Show 1
End If
End Sub
There was another suggestion to try: MyForm.Show False I did not know where to pace this similarly to the main suggested code to resolve.
VBA did not like me using "Me" (Me.Hide / Me.Show 1). I tried place the code snippet in several places ... the main opening macro, the navigation macro to and from the sheet that is affected, changing "Me" to the sheet name all to no avail. It is a sheet but since the unique variables are gathered here, it may loosely be viewed as a "Form".
I used to be a competent amateur but never an expert. I am appealing for a kind person to help direct me to overcome this "Excel 2013" problem. I have tried and failed many times and spent many hours trying to fix only to find the problem is because I'm using Excel 2013. There are even now no issues using Excel 2010 which I am able to access via a friend.
I'm sorry my first post is so detailed and hopefully not over-complex. I only wanted to give the correct information about the problem.

Related

Run a macro in an AddIn from a button on an Excel sheet [duplicate]

This question already has an answer here:
Can I assign a function in an excel add-in to a button in the workbook?
(1 answer)
Closed 3 years ago.
I would like to run a macro defined in an AddIn from a button on an excel sheet. I tried to enter the name of the macro in the "assign macro" dialog box that appears when right clicking the button (I don't know the exact English title of the dialog as I'm working with a German Excel version) in the formats
AddInName!MacroName and
'AddInName'!MacroName.
In both cases the name of the AddIn is stripped away automatically when I reopen the dialog.
The format "'AddInName'!MacroName" was rejected as "a too complex formula"
On the machine on that I am developing the AddIn this works but on another machine where the AddIn is running without problems this particular function does not work.
Is there a way to access a macro inside of an AddIn that may be located at different locations on different machines (C:/user/"user_name".../AddIns) ?
Long story, made very [long]: maybe.
You'll have to work out the file sharing and permissions between the two computers but you can use an AddIn on a shared network drive so it is entirely possible.
I would caution against using the same AddIn simultaneously between computers. It would be easier, safer, and more stable to make a copy.
You're on the right track with your string creation, but rather than adding it in the macro selection box, add it to the OnAction property of the button in the worksheet's code module.
I'm going from memory so I might be mistaken but I'm pretty sure your string will be built like this...
"'[addin.xlam]!project.module.macro'" \edit: tested and confirmed not to work
Note that there are there ticks, it is an outer "double quote" encapsulating an inner 'single quote'
You can also pass arguments to the macro with an appropriately built string too, it's relatively easy when using variables or integers but it gets tricky when you start using string literals.
Just finished my post to read this:
"#Peh: That might work, but then the excel sheet has to be an xlsm file what I wanted to avoid. – chrmue 9 mins ago"
Obviously that rules out my entire solution.
I spent several hours on this and all I've done is run around in circles.
The comments in my code appear to be wrong, and while I all passing parameters in my working code, I am only doing it within the same workbook and have failed every attempt to send them to another workbook via OnAction and even Application.Run
It may be a fools errand but I'm convinced it's possible so in but giving up.
I have a button on the sheet:
Shapes.Add xlButtonControl
It passes two arguments through a procedure:
OnAction = "'passthroughme ""passing"", ""through"" '"
But hithertofor, that's as far as it goes. No success reaching external workbook's while also including arguments.
I also have several examples of existing code that works just fine, but I haven't been able to get any is them to pass arguments to an external workbook:
Select Case Application.Run(testingFunction)
Application.Run procToCall, procArgs
testResult = Application.Run(testingFunction, testingArgs)
Application.Run "extractPDF." & loPDFvendors.ListColums(gTCN_PDFMAP_PROCLIST).DataBodyRange(mSupplierIndex), ws
Not giving up yet, but I am defeated for the moment

How to Prevent Free Distribution of Excel Spreadsheet

I reviewed the answer to the question at the link below. This seems to match my need, but I am not able to get it to work for me. What am I doing wrong so this will work. This code can be a great tool for me to limit the free distribution of my spreadsheet which I have commercialized.
Thank you for the help.
How to prevent free distribution of a commercial Excel spreadsheet
When I put the code into the modules and save the file, when the file is opened I am receiving the following error.
Compile Error:
Sub or Function not defined
It then highlights the reference to "Refresh_Serials".
I am running this currently on Excel 2007. Do I need to try it on a newer version of Excel maybe?
I have used the same code as included in the link below.
I would expect it to do as expected per the original post, although I am not 100% sure exactly what the outcome should be. Maybe part of my gap at this point is that I haven't yet established the HTML table. Could I use a "Google Sheet" instead with a table in it?
If you want this Workbook to be compatible for Specific Users only. Then one way to achieve it is to add a WorkBook_Open event. Like:
Private Sub Workbook_Open()
If Not Application.UserName = "Mohit Bansal" Then
MsgBox "Not the Correct User"
ThisWorkbook.Close False
End If
End Sub
Change the Name as Per the User, and lock the VBA Project. You can even make a list of names to check from if multiple users are going to use it.
This will make sure that only one user is able to use the Workbook.
There are obviously other complicated & efficient ways to achieve this, but I prefer this one for Simplicity.
Looking at the linked to code source (what the actions are that follow that line) and the coding style of the author I think that Refresh_Serials is in fact a label. It should be Refresh_Serials:. The lack of the ":" means the compiler is expecting a sub/function of that name. As there are no GoTo statements these labels, there is another proper label further on,SerialVerified:, are unnecessary and confusing. They could simply be comments. Better still, go more Single Responsibility Principle and have functions/subs with names akin to those labels and shift the relevant re-factored code into them.

Application.Goto Run-Time Error 5

I have been an active user of the information on this site and it has generally served me very well. I am struggling with this one however... I built an excel document a while back with this code:
Application.Goto Range("PART_NUMBERS").Cells(Application.Match(ROP_UPDATE.Label5.Caption, Range("PART_NUMBERS"), 0))
and it works beautifully! Basically it checks to see if a checkmark on a userform is checked and if it is it then finds the label associated with that checkmark and it finds it in a range where i can use other lines of code to do stuff. anyway... I am building another document where i need to do essentially the same thing and i built the code accordingly:
Application.Goto Range("po_s").Cells(Application.Match(PO_Checker.Label1.Caption, Range("po_s"), 0))
it gives me run-time error 5 every time. Identical code basically and i have looked over my named ranges and changed them a few times. I am stumped. Why does this code work good on my first document but not the one i am working on now? both are macro enabled. Any suggestions help. Thank you!

VBA not updating on Protected Sheet -- Excel Office 365

There are tons of questions already posted with a similar problem, but none of those solutions works for me. I'm using Office 365, so maybe it's something that changed there. Anyway, here is my issue.
I have a file that pulls info from one main tab into other tabs. On the subsequent tabs, I have VBA that auto-hides rows depending on the value that was pulled from the main tab. Anytime the data in the main tab is updated, the subsequent tabs should also update. I had an issue with making this work, but I worked it out by using another cell to store the previous value that had transferred (comparing them, and running the code any time they were dissimilar). The problem now is, of course, that it wont run when the tabs are protected. The tabs need to be protected to prevent end-users from corrupting the formulas and formatting, but I can't make it work with any of the solutions posted on StackOverflow. My code looks something like this:
Sub Worksheet_Calculate()
If Range("Old Value") <> Range("New Value").Value Then
Range("Old") = Range("New").Value
Rows.EntireRow.Hidden = False
<<Insert code to auto-hide based on "New Value" cell>>
End If
End Sub
I've tried adding Worksheet.Unprotect Password:= and Worksheet.Protect Password:= commands on either side of the If statement, and I get a 424 Object Required error. I've tried using the "UserInterfaceOnly = True" command with my password protection, and it changes nothing (still get the trying to change a protected sheet error). I've tried creating another subroutine for unprotecting and re-protecting, then using a GoTo to run the original subroutine; but that didn't work either. I see a lot of solutions using ActiveSheet commands, but I don't think I can use them. I'm updating the main tab, and the action is happening on another tab. I'm fairly new to coding, and I'm teaching myself as I go; so, I could be missing something obvious.
It works perfectly when unprotected, so I guess I may have to just leave it that way. I hate wasting time fixing the files when end-users do their best to ruin them, though, so I'd love to leave it protected.
This may not be the final answer, but I seem to have stumbled upon a solution. Since the only thing I want happening on the protected sheet is for rows to auto-hide, I left row formatting unprotected. It seems to work fine that way. You would think there's a way to run your VBA normally without having to jump through hoops because of protection....but, I'll take it for now.

Can VBScript run on protected sheet of an Excel?

I am using VBScript to make lots of calculations on different sheets on the same workbook. Now one concern is if somehow someone deleted any of the sheet, the script would then lead to massive data loss. Is there any way to protect it from users?
(Make sure you read the edit at the end of this answer)
I have similar workbooks I have made that use sheets like databases, so I understand your concern of protecting the information. If you are protecting the Workbook, it will prevent your macro from performing certain changes to the sheets/book. However, if you only want to protect the sheet contents, you can use the setting UserInterfaceOnly, which will allow your macro to run freely while still protecting the sheets from the users. You can detect if the sheets are protected when opened, and if not, protect them.
Sub test()
dim mySheet as worksheet
dim myPass as string
myPass = "password"
set mySheet = Excel.ActiveSheet
if mySheet.ProtectContents = False then
mySheet.Protect Password:=myPass, UserInterfaceOnly:=True
end if
'Enter your code here
mySheet.Unprotect Password:=myPass
End Sub
Furthermore, if you want to give the user the ability to unprotect the sheets after being warned, then you can use Custom UI Editor to remove the protect/unprotect sheets group from the review tab and then replace it with a customized button. I've done this in the past and it actually helped a lot with maintaining the sheets later. I've included a couple links on Custom UI Editor below.
Custom UI Editor Download
Custom UI Editor Tutorial - Change the Ribbon in Excel 2007 or
2010
EDIT:
At first glance I thought this question pertained to VBA (my bad). I believe the above code can still apply, just place the code within the tags and set the workbook and worksheet variables properly (not the way they are set above). If you don't already know how to set/reference your workbook/worksheetsheet objects, this forum post shows how. Albeit I don't normally work with VBscript, but the forum looks correct. Good luck!
i nw this was a few years ago, but i ran into it when searching for the answer, hopefully someone fins this helpfull.
First add a password to your workbook that way other users will only be able to open as read only.
http://www.k2e.com/tech-update/tips/728-tips-adding-a-password-to-make-an-excel-workbook-read-only
then to make as part of the vbscript when opening the excel file(s)
Set oExcel = CreateObject("Excel.Application")
Set oWorkbook = oExcel.Workbooks.Open(file.path,,,,"password","password",True,,True,True)
full list of switches can be found here:
http://msdn.microsoft.com/en-us/library/office/ff194819%28v=office.15%29.aspx
hope that helps, took me hours to figure this out.

Resources