(Google scripts App)How can I run the script in the function before the user sees the sheets themselves - google-sheets-api

Due to the time delay from opening the sheet to the triggering of the script that hides the secret sheets, the user still sees them at first. How can I make the script execute in the onOpen () function before showing the main (not hidden) sheets.

Related

Is there an event in Excel that runs when the application opens and before cells are calculated?

I'm trying to prevent Excel from recalculating cells containing my UDFs (because they run slowly).
My aim is to cache all the cell values by address in a dictionary store when the application first loads, the UDF will return a value from the store if it exists, otherwise it'll do a full recalculation.
I've attempted using the Workbook_Open() event to gather all the formulas in the sheet when the application loads. My issue is that the Workbook_Open() event fires after excel tries to recalculate all the cells.
Is there an event that runs before Workbook_Open()?

Pause VBA Macro to allow manual input of data

I have an Excel workbook macro that opens another workbook and starts copying data into it and formatting it. At one point in the process, I want the macro to pause and let the user manually enter data into the target workbook and then resume processing.
MsgBox, Application.Wait(), and Sleep are all application modal and will not let the user update anything in the other workbook while they are executing.
I found this while searching for a solution. It gets me halfway there in that I can manipulate the other sheet but only with my mouse. No keyboard presses get sent to the workbook.
Any ideas on getting all the way there?
I was thinking that I could just have two macros. The user would run one, then perform his manual tasks, then run the other. This appears to work but I would have to convert everything to globals so hopefully, someone has a better idea.
Thanks!
Depending on the macro being run to copy and paste, is the main concern with user intervention during execution of the macro getting the active cell/sheet (if being used) back to being active after the user manipulates something.
I'd recommend storing the active cell/sheet address in a variable prior to the Application.Wait() and then setting the active cell to that stored value on resume.
Without a posting of what your macro is doing though, it is hard to know if this suggestion helps your current situation.

VBA Freeze Screen Updating

Right off the bat, I am using Excel 2010 to run a macro, but "Screen Updating = False" is not going to work in this situation -
I have an Excel sheet with some attractive formatting where I display some stats. I have a macro that accesses an external program (CMS) to download updated stats a few times per minute. The macro turns off screen updating, accesses CMS, copies the data, pastes it onto another sheet in the workbook, then resumes screen updating. The idea is a live feed of this worksheet will be broadcast to people, and the stats will appear to magically update every few seconds.
The problem I'm running into is, every time I pull the CMS data, a small loading bar window pops up in the middle of the screen. Even though Excel Screen Updating is off, I haven't found a way to hide or move this loading bar out of the way. I don't want the stream to have a loading bar appearing and lingering every time it updates.
What I'd like to do is freeze Windows' screen for a second while the data is being accessed. Is there any built-in library I could use, or other-language script I could invoke at the start of the function to freeze the Windows display while it runs, and resume it after it's complete?
You can try:
Application.DisplayAlerts = False
Application.EnableEvents = False
and obvously turn them back on again after your code has executed

CommandButton Clicking vs Executing from VBA Editor,

If you have look at these two captured images...
Basically, stepping into the next line should not change the selected tab as shown here. This is what happens if I click F5 from the VBA Editor to execute the sub
But when I actually run it using a linked command button which suppose to be doing the exactly same thing (photo shown down the thread). but what happens is this,
Stepping into the next line actually somehow changes the tab!
There is noting in the first break point line that tells excel to select another tab... why is this doing this.
if I run it using F8, actually this problems goes away.
UPDATED=============================================================
I come across some weird behaviour in the Excel VBA and can't explain why its doing it.
Sub run_simulation()
ActiveWorkbook.Worksheets("Run Simulation").Select
ActiveSheet.CommandButton1.value = True
End Sub
This subroutine selects a sheets then simulates the clicking of a button 'CommandButton1'.
When I execute this from the play icon within the VBA Editor it runs fine but when I run this 'run_simulation' subroutine from a linked button on another sheet... like this
an error returns saying that the selected sheet "run_simulation" is protected and needs to be unprotected before proceeding... the thing is it unprotects the sheets automatically when the commandButton1 is clicked.
The Worksheet.Protect method has a little-used UserInterfaceOnly parameter.
From MSDN:
UserInterfaceOnly (optional) - True to protect the user interface, but not macros. If this argument is omitted, protection applies both to macros and to the user interface.
Set this to True when setting the worksheet protection and you will be able to manipulate the worksheet objects programmatically.

VBA code to run another password-ed VBA code

I have a VBA macro, developed by a third party, and which is password-protected. When the macro finishes what is is supposed to do, it shows a message box, and to continue beyond that the user needs to click a button. Before the button is clicked, you cannot do anything else .
I need to run that macro on several files. Is there a way to bypass the message box, and just call another instance of the macro, on a different file...?