ExcelScript - run on cell selection / editing (bind?) - excel

How can I run a piece of code on a cell selection? And how can I run it again, when I start editing the value in the cell?
I been going through the documentation, and in no way I can find anything (a specific binding???) to achieve the desired result.

You can use workbook.getActiveCell() to run a piece of code on a cell selection, but the second part to your question is not possible as Office Scripts does not support events that trigger scripts to run.

Related

Excel Makro to copy into another program

For my work i need to track what cases i did. Right now i note all the case numbers in an excel file where i also sort them to the categorie they belong. At the end of every week i then have to put in the numbers in our tracking tool with copy and paste (tracking tool isnt on the same desktop i work on so i cant do it directly)
So i thought maybe it would be possible to write a macro in the excel file that does the copy paste for me but i already fail when i want to switch from the excel to the tracking tool
I tried shell activate and windows activate but i only get run time errors
Im grateful for any help even different approches
Please add screenshots and more explaination of the scenario so we could have better insights

How to avoid reloading data in each run

How can I avoid reloading data each time when I want to check if my script works? I work with spyder and python.
I have to load around 1000 .csv files, it takes just a few seconds but it is unnecessary to repeat this step each time I change a parameter or a name somewhere else in the code.
One simple option is to comment a part of code. What would be a more efficient way?
(Spyder maintainer here) You can use cells in Spyder, which are blocks of code delimited by comments of the form #%%. You can evaluate cells with keyboard shortcuts Shift+Enter (run and advance to the next cell) or Ctrl+Enter (run and stay in the same cell).
This way you can have a cell to load your files and then another cell to do you computations with them, like this
#%%
data = load_my_files('my-dir')
#%%
compute(data)

Convert an excel range into image without copy and paste

I am looking for a solution were a given excel range can be converted to an image without copy and paste or without putting anything in clipboard.
The reason for this is because the VBA code will be running in the background and the user will continue their regular work. So when they do any copy and paste activity happens 'oRange.CopyPicture xlScreen, xlPicture' code hits an error.
The tool will run every 60 seconds.
I have checked a lot of web portals to find an answer, but most of them are limited to 'CopyPicture'. One webpage example given below.
http://vbadud.blogspot.com/2010/06/how-to-save-excel-range-as-image-using.html
Can someone please help me.
Found a solution, might not directly solve this. I have created another instance of windows log in and run this Marco at regular intervals in that instance.
This way we have two different clip boards that will not conflict.

Making use of selected or clicked cell without VBA

A tricky one, I assume. However, is there a way to make use of a selected or clicked cell in Excel somehow without the need for VBA?
(I know how to do it with VBA, but macros are macros, but if you want to give workbooks to people...)
For instance, I would like to make some of the content in the freezed section to be dependent on where in the sheet someone is. It would be optimal, if the selected cell/row would be trigger enough.
It would be also okay, if clicking a cell (e.g. a link navigating in the sheet) would trigger the conent to change. Hence, a solution would be to make a hyperlink change a value in some cell somewhere. I know, this is a different question, but it should be all accomplishing the same goal of the line on top ;-)
Thanks a lot!
You cannot change values or display of another cell with formula or functions.
The hyperlink will send you to another location but won't change the freezed part, except if you only freeze rows and the hyperlink send you to a further column. But you will have then to really think about your layout very precisely. Moreover, the user will even less understand what happens unless you can design a great UI (but Excel may not be the best tool though).
Some tips:
Use hyperlinks but on differents sheets
Use "transparent" macros (without big buttons but rather event vba as you pointed out)
Sorry i don't have a magical solution.

Can you detect if and excel find and replace is active during worksheet_change()?

I've just crashed excel using amazon spreadsheet to update feed.
When doing find and replace [replace all] with 2 cells selected after the first replacement the worksheet_change() function finished with the whole spreadsheet selected.
This meant that the replacements took place outside of the original area.
Unfortunatly the replcement text included the find text and each replacement re-selected the entire area excel ran until it ran out of space then crashed.
Pressing control-break brings up the vba dialog STOP/CONTINUE/DEBUG.
DEBUG is greyed out as amazon had protected the sheet.
STOP would stop one run but would then continue to crash.
CONTINUE would switch back to the current change and continue to crash.
Is there any way to detect if a find&replace operation is in action whilst executing excel vba?
Regards John
Unfortunately, there is no way to know what is triggering the Worksheet.Change event in this case. All you can know is that some change to the worksheet's contents has occurred and which cells within the worksheet has changed. You cannot know, however, what code was called to make the changes, or even if it was code that made the changes, as the user can cause the Worksheet.Change event to fire as well.
I see two issues with what you describe above:
You stated that you commenced the find-replace action with two cells selected. But the behavior that you describe suggests that you only had one cell selected. If you have two or more cells selected, then the find-replace action occurs only within the selected range. If you have only one cell selected, however, the find-replace occurs over all cells in the worksheet. So I strongly suspect that you had only one cell selected when you started the find-replace operation, not two.
The fact that the find text and the replace text overlap does not sound like a great idea, but it should not produce any problems with the kind of non-terminating recursion that you are describing. Is it possible that your worksheet_change() function that is handling the Worksheet.Change event is itself directly or indirectly invoking another find-replace action? If this is the case, then you very well could get the infinite recursion.
-- Mike

Resources