Google apps script for Spreadsheets: How to hide a helper function in Script manager? - spreadsheet

I have customised a menu in Google Spreadsheet using Google Apps Script.
The problem I have is that all the helper functions I am using are listed when I press Script Manager.
I would like to hide them, I have read that if I put an underscore at the end of the function name, but it didn't work.
From documentation they say that the underscore at the end makes that the function is only callable from another function and not the editor, but as you can see in the image, it is not working for me:

The underscore does nothing more than inhibit the function from showing in the Run from Script Editor dropdown.
Running functions. Any function can be invoked directly from the Script Editor, except those with a name that ends with an underscore, which can only be called from other functions.
You cannot hide code in the script editor.

Related

New to Access How to run VBA code that doesn't have Sub?

Hi, I'm new to Access and I have a quick question.
I have a code that does not have 'sub'. And I was wondering how can I execute my code when I don't see any on Macro window? (Refer to the image attached)
My code start with function and declaration of variables!
It's very straight forward question but please comment below for any clarification if needed!
For you to be able to run a function with the press of a button for example, you must:
a) Put the function in a standard module, within the vba editor. Move the code to a new module and then call the function from a macro.
Or
b) Run the function from within an event vba sub like the click of button.
For both a sub, and a function in a code module, you can normally place the cursor in the sub/function and hit F5, and the code will run.
The above works for both a sub and function.
However, WHEN the sub/function has a parameter(s), then the F5 option will not work. In your screen shot the given function requires a parameter, so the long standing F5 to run such code as per above will not work. What occurs in this case is the macro prompt will launch as you point out.
Two suggestions:
Whack ctrl-g and your cursor should now be in the debug window, you can type in the name of the function (or sub) and SUPPLY the parameter.
Eg:
Test9999 "my first prameter"
The other means is to write a test code stub that passes the parmaters like this:
Public Sub RunMyFunction()
Test8888 "my paramter"
End Sub
And thus you can now hit F5. So you don’t need to run the code from a form or a button as suggested here. However, the instant the sub/function has a parameter(s), then you lose the F5 to run the code from the VBA IDE. You have to write a code stub, or as noted enter the function name + supply the required parameters of the correct type in the debug window to run the function.
However, to be fair, you can build a test form, and place code behind a button, but your question was in the context of the IDE and use of F5 to run such code.

Changing ActiveX Component Name Properties Dynamically in Word

I am trying to develop a dynamic user form in a Word document that will create an ActiveX radio button with a generic name and then rename that created radio button to make it have a specific number based on its location in the form.
So far I believe I have all the components to write the code because I am able to create the button. I create the button by using VBA to import a quick part that has the radio button with a defined radioButtonX name and I am able to change the name property of that radio button to radioButton1 for example. The problem that I am running into is that my code will insert the quick part with the generic radioButtonX name and then fail to change the radio button name because it says that radioButtonX does not exist. However, I can manually run the second part of the code after radioButtonX has been inserted and I am able to successfully change the radio button name giving me the end result that I am looking for in two separate steps.
I am a self taught VBA scripter for the last year so I am far from an expert at coding. A few of the strategies that I have taken so far were to:
Put in waits (thinking that pausing the script would give the script time to recognize the new radio button)
Separated the code into different subs having one sub create the radio button and then call a sub to change the name (hoping this would update VBA)
Separated the code into different modules having one modules create the radio button and then call a modules to change the name (hoping this would update VBA)
I was hoping for some advice, strategies, or sample codes that I can use to get VBA to recognize the new radio button that I have inserted while the code was running. Another thought that I had was maybe there is a command that exists that will have VBA refresh its knowledge of variables, but I have not have any luck finding something like that in my web searches to this point.
I tried to simplify the code that I was working on and pull out the code that would perform the function that I was requesting. Running the simpler code was successful and listed below.
Private Sub AddRadioButton()
Selection.TypeText Text:="TestRadioButton"
Selection.Range.InsertAutoText
ActiveWindow.View.ShowXMLMarkup = wdToggle
ChangeButtonName
End Sub
Private Sub ChangeButtonName()
ThisDocument.radioButtonX.Name = "radioButton1"
End Sub
For this script to work you must create a quick part or a radio button that is named TestRadioButton. I think now the root issue has to deal with timing that looked like it wasn't working because the script that this code came from is using a quick part with multiple generic radio buttons in it so the script executing does not recognize the new radio buttons while running.

How do I add a User Defined Function to Excel?

I have a simple stored procedure that returns a Description and a Name when you give it a ID. I need to enable this inline in multiple Excel Sheets. Something like =ItemLookup('12345') that would then return the aforementioned info.
I have not done a lot with Excel programming and am simply wondering what my options are for tackling this. Is this a VBA thing or should this be an external DLL that I COM register? Both felt like overkill but then I realized I had no idea if they were. I really wanted to use VSTO for this but it sounds like that is not possible for Cell level UDF's without having to modifiy each Workbook with some VBA.
The best way to add UDF functions to Excel is with Excel-DNA (which is a free, open-source library I develop), and any of the .NET languages - VB.NET, C# and F# are all fine.
To get started you make a new 'Class Library' project in Visual Studio (any edition), install the 'Excel-DNA' package from the NuGet package manager, and add your code:
Public Module MyDataAccessFunctions
<ExcelFunction(Description:="Gets the Item from the database")>
Public Function ItemLookup(code As String) As String
' Here you have to do some work to get the data
Return "Hello " & code
End Function
End Module
Pressing F5 builds and starts Excel, and you're done - try putting =ItemLookup("Paladin") into a cell.
The resulting add-in is a single .xll file, which you can copy and use on any machine that has .NET without any installation or admin permissions. It works with old Excel versions too.
The best place for support (including absolute beginners' questions) is the Excel-DNA Google group.
You can use Excel to create a VBA UDF pretty easily, just hit alt+f8, right click your project in the project hierarchy on the left of the screen, and click add module.
Here is a quick Hello World function you can just paste into the module, then click play (or alt+f8 from worksheets)
sub test()
msgbox "helloworld"
end sub
If it was me, I would probably just create a list of the file paths that need to be searched. Then create a VBA macro that opens them in excel, searches them for the key, and returns other information from the row the key was found on.
You can open files with the 'Application.Open' method, simply pass in
the file path as an argument. 'Application.Open' returns a workbook
object.
Each workbook will have several worksheets, you can access them
through the workbook's 'Worksheet' property
Getting each used cell in a workbook can be done via looping through the 'UsedRange'
property in each worksheet
Get the value of a cell for comparison from the cell's 'value' property
Cells also have a 'row' property so you can find other items on the same row
If you're used to VBA you could get this running in less than an hour. But since you're just starting out it'll probably take a 3+ hours since you'll have more research/debugging

Function Arguments dialog executes UDF when all non-optional arguments are filled

Let's say I have a function foo(bar as String, Optional baz as String), that does some really heavy lifting (e.g. connecting to database, etc.). The problem we're seeing is that when Function Arguments dialog is displayed (by clicking on Fx icon next to formula to bring up that dialog) and the user puts a value of bar, Excel decides to execute a function right away, without waiting for the user to enter a value of baz or to press Ok. Is there a way to detect in UDF that the user is using this dialog to basically not do anything? In the screenshot, you can see that Excel shows Formula result in the bottom left corner once value for Bar is entered.
From my UDF page:
Excel User-defined Functions
To detect when a VBA UDf is being called from the function wizard you can add this code to the UDF
If (Not Application.CommandBars("Standard").Controls(1).Enabled) Then Exit Function
This code depends on the fact that when using the function wizard most icons in the toolbars are disabled.
A solution is also possible by using the Windows API to check if the Function Wizard window is showing and has the same process ID as the current Excel process.

MS Access RunCode Macro cannot find my procedure

I'm only posting this since I wasn't able to find a solution anywhere. I finally figured it out. Kind of silly really.
When using the RunCode property within an Access Macro, I was trying to run a Sub from my global module. I was getting the error "The expression you entered has a function name that database can't find." I couldn't figure out what the issue was. I followed the advice of everyone that posted on this issue, which was mostly the following:
Use () at the end of the procedure name
DO NOT use the "=" before the procedure name
Still didn't work!
THEN I read the error message carefully. It mentions that it could not find the FUNCTION name. Apparently, the RunCode property specifically requires a "Function" not a Sub. So, I simply changed my Sub to Function and it worked fine!
Hope this helps.
Another solution that worked for me:
The module name can NOT have the same name as the procedure(s) in the module(s).
I had a similar issue with the error message. My VBA code had the following declaration:
private function MyFunction()
....
end function
I removed private declaration to get the Macro Runcode to execute the MyFunction()
For example:
Function MyFunction()
End Function
My mistake was putting the function in a Class Module instead of a regular module.
Access 2013: A function called with MyFunction() from RunCode where MyFunction does not exist gives me error 2425. None of the above work for me, however, and I was still getting Error Number 2001 when the function exists and is public. Database is in a Trusted Location. No compile errors, but something in MyFunction did not work, namely
DoCmd.ShowAllRecords
after GoToControl worked to select my subform. Real problem was my code to remove a filter with VBA. Manual for ShowAllRecords seems to indicate that this should work, but replacing DoCmd.ShowAllRecords with
DoCmd.RunCommand acCmdRemoveFilterSort
fixed my problem.
The database seems to need to have objects in it other than the VBA function being called as well. Without other objects (specifically a table in my case), the function is unable to be found from within the calling environment (eg Excel VBA).
Access Office 365: My subroutine works when called from within VBA and used to work in Macros. Moved function text to a separate module, saved it by itself. Gave the module (not class) a unique name.
I was borrowing a "template" vbasic text from online as a shell. And while I renamed the function in the code section, MSAccess/Vbasic did not show the name change in the function heading of the Module box so when I ran the macro which called this function it said it couldn't find it. Tried repeatedly to fix. Then I noticed the name was different in the code section of vbasic versus the heading of the function dialog box. So I changed the name manually in the heading box and it prompted me to save which I did and now it works. Maybe this is why snake software is so popular. :)
My VSTO C# calls to app.Run("MyMacro") stopped working suddenly and the error message started printing. ("Access cannot find the procedure MyMacro.")
The problem on my machine was that my code (which connected to a running instance of Access) was connecting to a zombie database instance that did not have that VBA macro in it. Go figure. The zombie instance did not show in the Taskbar, in the Alt-TAB display, or in a list of windows that I printed out using a console program.
The way I discovered it was to have my VSTO code print out the name of the database that it was connecting to. The Access database was one that I had been working with earlier in the day, without errors. I had closed the Access app holding it successfully hours before I tried running MyMacro.
I can't think of anything that I did that was unusual, other than upgrading VStudio to the latest version. Probably a reboot will fix things. What a weird problem.