How to delete a large number of command buttons in excel - excel

I have a macro that I have designed to retrieve information from the internet and then to process that information into formats I want. My first worksheet in the workbook functions as my command page and all of the subsequent worksheets are populated based on what I tell the command page I want.
I have assigned control buttons on the command page to all of the various functions I want the macro to execute on the data retrieved from the web so I can select which functions I want applied. However, I believe that somewhere along the way I told my code to make copies of 1 certain command button.
There are now over 7000 command buttons for one function. Thank fully they are all stacked on one another so it isn't obvious, however it is starting to slow my excel down.
Is there any way to manage all of you buttons and then to select the ones you wish to delete?
Maybe a macro that deletes all duplicate command button names would do the trick? Before I tried this method, I wanted to see if there was an easier fix to my problem.

This should work for you:
Shift+Ctrl+Click on the button to select it
Press Ctrl+a to have it select all of them
Then Ctrl+Click the button to de-select the top-most button
Press the Del key to delete all selected objects.

Related

Call 'Move or Copy' Dialog

In EXCEL there is an on-board 'Move or Copy' dialog, which can be started by clicking right on one or more sheets. The advantage of this feature is that a little window (see picture) is opened, and the user can select the destination. I wanted to add this routine to an existing sub. I know how to copy a sheet using VBA, that's not a problem, I wanted the same little window, and I was wondering if I can use the on-board routine. I have tried recording, but the window for selecting the destination did not occur in the code. Of course, I can simply rebuilt it, but why reinventing the wheel?
Is there a way of calling the routine?
It's a built-in dialog:
application.Dialogs(xldialogworkbookmove).Show
You can also use xldialogworkbookcopy and you should basically get the same dialog but with the checkbox at the bottom checked.

work in excel while the macro works, how to perform this task?

As we know, usually after a macro is run and before until macro finishes, we cannot do anything in this excel document.
This is sometimes a little inconvenient, and (let's imagine) I do not want to wait for a long time, and it would be nice to do something in the same document in parallel.
Is it possible? If YES, How?
No, this is not possible.
Excel does not support running macros in a secondary thread, so there's no way to do what you're asking. The reason is pretty clear - how would it work if your macro is doing things on cells that the user can edit/insert/delete while the macro is running, when that can affect the behavior of the macro?
No, although there is a potential workaround described in the below link that may be of help.
https://analystcave.com/excel-multithreading-vba-with-vba-worker-threads/
Maybe you can try to do something using Application.ontime, but you should try not to use macros where it will select cells, sheets, for example: Sheets(1).Activate, Range("A1").Select. Using Application.ontime you can do a chronometer for example and continue to select or insert values in a cell.
Excel/VBA is definitely NOT a multi-threading technology/solution. If you have to run several Excel processes in parallel, consider starting one or more new instances of Excel.
Opening a second instance of Microsoft Excel causes Windows to load a new copy of the program into memory. This can be useful when you find yourself waiting a long time for Excel to complete complex operations in a large spreadsheet. Opening a second instance of Excel allows you to work with on a different spreadsheet while the first instance of the program is busy.
Desktop View
1. Open your first instance of Excel, and then right-click the Excel icon on the Desktop taskbar.
2. Hold down the "Alt" key and select "Excel 2013" from the pop-up menu.
3. Continue holding down the "Alt" key until you see a prompt asking you if you want to start a new instance of Excel. Click "Yes" to open the new instance.
Start Screen
1. Open your first instance of Excel, and then right-click the Excel tile on the Start screen.
2. Hold down the "Alt" key and click "Open New Window" on the Start screen taskbar.
3. Continue holding down the "Alt" key until you see a prompt asking you if you want to start a new instance of Excel. Click "Yes" to open the new instance.
Now, when you open the Task Manager, you see two instances of Excel running.
You can run these two jobs/tasks in these two instances of Excel, all in parallel!!
Insert DoEvents between your code.
Sub test2()
Do
'.....
DoEvents '<~ While the macro is running you can do other things in the Excel document.
Loop
End Sub

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.

Can not delete Command Button from worksheet without Excel crashing

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

Reference Excel cells in Word

Does anyone know of a pre-packaged solution for referencing Excel cells directly in a Word document?
For example,
{[TestExcel]Tab1!A1}
Dear Mr. {[TestExcel]Tab1!A2},
Our systems have alerted us that your account {TestExcel]Tab1!AccountNumber} is overdue. Please remit payment of {TestExcel]Tab1!PaymentDue} immediately.
This example uses a hypothetical { } syntax, where the contents are standard Excel formula.
Every solution I've seen uses custom VBA to accomplish this. It seems like an extremely common need for which there should be some good 3rd party software available that lets non-technical users accomplish this task.
As indicated in the example above both named ranges and standard cell references would need to be supported.
Yes.
Step 1: Copy the excel cell.
Step 2: Go to your word document where you want to paste the reference.
Step 3: Right click
Step 4: Under paste options, select "link with source formatting" or "link and merge formatting".
I tried #Green Demon's method, but the two Paste Options listed were not present for me (Office 2013). I only had Keep Source Formatting, Merge Formatting, and Keep Text Only. However, I poked around and found the Paste Special, which was hidden on the Ribbon
The instructions are as follows:
Copy the Excel range.
Go to your Word document, and left click where you want to paste the Excel range.
Click on Paste Special from the Ribbon as shown below, or type Ctrl+Alt+V.
Click on the Paste link radio button.
Click on Microsoft Excel Worksheet Object. The Paste Special dialog box should look something like this:
Click OK.
The range should now be pasted in your document, and if you save, close, and re-open the Word document, you will be prompted about whether or not you want to "update this document with the data from the linked files," which works the same way as it does if you're doing Excel-to-Excel linking.
This feature is fantastic, and I'm so happy to have found it today. However, in my brief experience using it, having these Word-to-Excel links dramatically increases the amount of time it takes to open your Word document, even before it prompts you about updating. After that, the act of updating the Excel links takes much longer than it would if you were doing the same linking Excel-to-Excel. All of my work is done on network-share files, so YMMV.
While Will's solution indeed links from the Cell objet, the content is inserted as a picture.
In the same dialog, selecting "Unformatted Unicode Text" instead will link and insert only the cell's content, which is desirable if you apply custom formatting on your text.
Unfortunately, this action only works for a single cell. Copying multiple cells will result in a text block with individual cell content seperated by tabs or line skip, with the entire block considered linked and entire. The solution is to link individual cells using this method.
This can become tedious if you plan on linking large portions of table from Excel, as for every cell the dialog must be invoked. It can be sped up by using hotkeys, but the sequence gets tedious:
alt,h,v,s, then alt+l, tab, ↓, and finally Enter
Obviously this is not practial for large numbers of cells. A AutoHotkey script can help but it third party grafted solution, on par with using VBA scripts.
alt+h+v+l works too. If you're building big documents clicking the ribbon every time gets murderous after a while.
As this is still a problem but the other answers do not take into account the latest development in word, there is a new solution, editing Green Demons answer:
Step 1: Copy the excel cell.
Step 2: Go to your word document where you want to paste the reference.
Step 3: go to the "home" tab
Step 4: Under paste options, go to "Paste Special", click on "paste link", click on "Unformatted Text".
This solves the issue others were having with the new lines that you would otherwise have with just Green Demons' solution.
Hope this still helps others.

Resources