Can not delete Command Button from worksheet without Excel crashing - excel

I have a worksheet that I want to delete. Originally it contained 3830 rows. When trying to delete the worksheet, Excel would crash, and completely close. I thought this might be due to the amount of data on the worksheet, and the presence of a formula in one of the columns. So I removed the formula from the column in sections, and then deleted rows in blocks, saving each time. I removed the data until there were only 30 rows left, and still could not delete the worksheet without a crash. After this I went through the VBA and removed any references to the sheet, in case there was some kind of dependency problem. This still did not allow me to delete the worksheet.
As well as the data there is a Command Button embedded in the worksheet, which I have determined is the cause of the problem. The button has no related click event - clicking on it appears to do nothing.
To modify the button I have to enable Design Mode, which I presume is because it is an Active X control. If I try to cut the button via the Right click option, Excel crashes. If I try to delete the button by selecting it and hitting the delete key, Excel crashes. The button is called 'Sort' instead of 'Command Button 1' or similar, but I have not been able to find a reference to this name in the Name Manager.
I have been through the object properties, and can Edit the Command Button Object, moving the object, resizing it, etc. I have also been through Format Control, but with no success. Originally the object was locked, but the worksheet was not. I have unlocked the object, but again this has made no difference.
I have also created a new Active X Command Button and a Form Controls Command Button on the worksheet, and have been able to delete both without any problem. The workbook in question contains a lot of worksheets so ideally I want to be able to resolve this issue without needing to copy each of the worksheets I want to keep to a new workbook, or a similar fix.
Any suggestions would be gratefully received!

I had the same issue. I added the command button and for some reason, when I tried removing it, the excel crashed out.
Solution:
Create a blank excel file and save it with a new name.
Open the file with the command object.
Right click on the sheet and use MoveOrCopy.
Check copy option and copy the sheet across to the newly created
file.
All your formulas, NamedCells get copied across successfully. If you got any VB code, you need to copy it manually.

You can disable automatic calculation of your excel workbook.
Using VBA Code: Application.Calculation = xlManual
Manually: Formluas > Calculaitions Options > Manual
Save the file and then try.
As there is only one button on the sheet and assuming n oother data you can try to delete the sheet using VBA
ThisWorkbook.Sheets("SheetName").Delete

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.

Excel VBA Slow Opening

We have an excel workbook (xlsm) which has an embedded VBA code, which looks up the distance between two points using the getgoogledistance module.
Since we have added this to the workbook, it take a very long time to open sometimes in excess of 10 minutes..
I suspect on opening the workbook, it is trying to update all of the entries, hence why it is slow to open.
Is there a way in which I could add a button to the worksheet and rather than on 'open' update the necessary cells, when this button is clicked it updated all the cells?
Yes, you need to go to the options, then customize menu and from the list on the right, check the Developer menu.
Back to Excel, you'll be able to add controls such as push buttons and attach macros to them.

Missing DataValidation DataSource

I am working on an excel spreadsheet. I have a dropdown with values. I need to add a value in there.
There is no macro and there is no connection. The only thing I found was:
I selected the cell at hand
Data -> DataValidation
In the source i can see this string =Variables!$D$1:$D$23
I do not have a sheet called variables or anything close to the word variables in any of the sheets. Where can this be coming from?
There is also protection on the workbook but not the individual sheets. Could this be the issue?
Thank you
You can usually check the contents of a hidden sheet quite easy using the Immediate Window.
So open the VBA editor (Alt-F11), go to the Immediate window (Ctrl-G), and try:
?Variables.[D17]
If this works, you can repeat this to see the other 22 validation values (or write a small sub, using Debug.Print ubstead of ?).

Macro button under customized ribbon tab tries to open old Excel file

I created a custom ribbon tab on my Excel like Excel_app_v1.xlsm, and a button under this ribbon tab is connected to a macro. So when I click this button, the macro does some table importing applications.
The first strange thing is that I created this ribbon tab and the button for only this Excel file, but the ribbon tab and the button appear in all other Excel files, even if the original Excel file Excel_app_v1.xlsm is not open.
The second problem is that I created a second version of my previous Excel file with "Save-as" option. So the new Excel file is like Excel_app_v2.xlsm. When I click the button under the ribbon tab, it opens the first Excel file Excel_app_v1.xlsm, even if it is not open. I deleted the first Excel file, but then I got an error like "Couldn't find the Excel_app_v1.xlsm on the path".
So obviously the macro button under the customized ribbon tab is linked to the first Excel file, but I couldn't find the menu option to change this. I added ThisWorkbook before all the sheet expressions in the vba code, but it didn't solve the problem. The button-click is still trying to open the old excel file.
The VBA code is below. The button is linked to the Sub ImportTable. Firstly it asks the user if the user wants to continue with the process. It opens the previous Excel file right after clicking on the button, at the same time as the Message Box appears.
Sub ImportTable()
Application.ScreenUpdating = False
YearMonth = ThisWorkbook.Sheets("tab1").Cells(11, 2).Value
' The Macro button opens the previous Excel file before clicking Yes or No on the message box
answer = MsgBox("Warning! Brings the newest source file. You want to continue?", vbYesNo + vbQuestion, "")
If answer = vbYes Then
RunSASCodeViaBatFile ' Another Sub which runs bat file to run a SAS-code. But it doesn't matter. Because the problem happens before I click on Yes or No.
InsertSASFileIntoExcel
Else ' Nothing happens if clicking No on the Message Box
End If
End Sub
The clue to fixing this quickly was posted below by roncruiser, with one slight twist.
Everyone on the web seems to feel that PERSONAL.XLSB is the key here — nope. In fact, playing with that file only confounded me for even longer. Here's what I did instead:
Right click the Ribbon and select Customize The Ribbon;
Navigate to the offending macros that you've installed with buttons;
Find and click on Import/Export;
Export your custom buttons (the macros will go right along just fine);
Open that resulting file, and edit out the offending references to the other file that's causing you so much grief — example:
<mso:button idQ="x1:HideRows_0_EA10D6" label="HideRows" imageMso="_3DPerspectiveDecrease" onAction="!HideRows" visible="true"/>
I took out everything after idQ-"x1... up to the actual name of the macro. I also took out the same external reference found in onAction="... Take everything up to the bang mark.
Save this under whatever name you wish, but with the same extension (for my setup, it was called ExportedCustomizations.exportedUI (yes, that long an extension));
Repeat the first few steps here, but this time import your edited file.
Voila, all is golden.
No messing around with wiping out existing work and starting all over. Worked a charm for me, so a big tip o' The Hat to roncruiser for the clue.
Just to confirm what sumgain have write above.
It works perfectly just do as he said : remove the part after the "x1:" that refers to a specific workbook until the begining of the maccro's name.
example :
When you export your custom ribbon with the maccro attached to it it will be write like below :
idQ="x1:C:_FolderName_Filename.xlsm_Fill_Formulas_Cells"
THen you remove the part mentionned and it will become like that :
idQ="x1:Fill_Formulas_Cells"
Same for onAction keep only the Maccro Name
Then it will works perfectly as long as you the maccro's name in the workbook stay consistent if you modified the Macros name then you have to modified it in the exportedUI file.
Then when you will reload the new file you can check in the Excel Options customize ribbon on the customize button if you put the pointer on you will see "Maccro: Name of your maccro"
And not the path of the file the maccro was from.
No need to use custom UI editor or any other things such as personnal maccro at least for that and if you are not bother to have custom ribbon in all of your woorkbook.
As well it is obvious but still good to remind it, you need to have the maccro in the workbook this procedure is just there to call the maccro that are associate to the workbook, it doesn't contain the code of the maccro.
Cheers
Romain
Does this still work? I have done this in the past with success but can't seem to get it to work now.
I export the file, edit it and import it back in.
it appears to work, but when i close the Ribbon options pane, my custom buttons disappear.
Same exact thing happened to me. There's a way to get around this.
By default, when you create a macro in Excel and run that macro through a custom ribbon button, that ribbon button macro works only in the workbook that contains it.
To get around this and have the button macros work in all workbooks, you'll need to create a Personal Macro Workbook. Then any macros that you store in your personal workbook on a computer become available to you in any workbook whenever you start Excel on that same computer.
Create a Personal Macro Workbook
To get the same ribbon button macros to work on another computer, you'll need to copy the Personal Macro Workbook to another computer and store it in the XLSTART folder. The link above has all the information you'll need.
Note: Delete the old ribbon button macros. Make sure you create new ribbon button macros that reference the macros from your Personal Macro Workbook.

Formulas within a table that reference an external workbook cause warning message when updating links

If I add a formula referencing another workbook, and the formula is within a table, the warning message "Warning: Open source to update values" is displayed when manually updating links.
I am using Excel 2010, but I can also observe the same behavior using Excel 2013.
Steps to reproduce the behavior:
Create a workbook named A.xlsx and save it to your desktop.
Create a workbook named B.xlsx and save it to your desktop.
Open B.xlsx and insert a table on any spreadsheet. On any column of the table, add a formula that references A.xlsx, e.g. a formula directly refencing a cell on A.xlsx.
On the Data tab, in the Connections group, click Edit Links. Chose A.xlsx as the source and click on "Update Values". The warning message "Warning: Open source to update values" is displayed.
All the values seem to be updated without errors, despite the warning message.
Question: Is this warning message spurious, or does it really indicate a failure to update the linked values in any way?
As noted above, the values seem to be correctly updated in my tests, but the warning message is still a bit disturbing as it may indicate some issue I was not able to detect.
If I précis what is detailed here I may corrupt the proper explanation but as I understand it, basically this is to warn you that the workbook in which you see this message is using values stored in that workbook to represent those linked to in the other workbook. If the other workbook is closed the stored values may not have been updated by changes in the other workbook so to be sure open the other workbook to refresh the links.
If the other workbook is actually open at the time then I presume it is either an anomaly of Tables or perhaps a warning to cover a situation such as a link to an ‘open’ PivotTable but one that may not be in a refreshed state.
As far as the workbook with the warning is concerned the data is 'clean' but it is unable to read 'dirty' flags in the other workbook.
I'm only a recent user, and i was experiencing the same thing- after some research i came across this code-
I adapted it for my own workbook and pasted it in the "ThisWorkbook" object in VBA for the destination workbook.
What it does is temporarily open/refresh/save and close the source application. If the connection to your source file is ok, it shouldn't take too long to update, but do be careful while trying to open it without a connection.
Private Sub Workbook_Open()
Workbooks.Open ("C:\Users\address_of_source_workbook")
Dim i As Integer
For i = 1 To ActiveWorkbook.Connections.Count
ActiveWorkbook.Connections.Item(i).Refresh
Next i
Workbooks("name_of_source_workbook").Save
Workbooks("name_of_source_workbook").Close
End Sub
Hope this helps!

Resources