Excel workbooks have a CustomDocumentProperties collection. This collection is of type DocumentProperties and has an Add method that I'm attempting to call from MATLAB.
If I call the invoke method on the collection I see:
>> workbook.CustomDocumentProperties.invoke
Item = handle Item(handle, Variant, int32)
Add = handle Add(handle, string, bool, int32, Variant(Optional))
I assume this means the Add method requires a string, boolean, int32, and an optional variant, and this matches with the Microsoft documentation for the Add method.
However, all combination of inputs I've tried to this function result in an error. For example:
workbook.CustomDocumentProperties.Add('MyProp', true, int32(1), true);
Results in the error:
Invoke Error: Incorrect number of arguments
If I supply 7 or more arguments then I get the error:
Error: Invalid number is arguments. This method can take maximum 6 arguments
If I supply anything other than a string as the first argument I get the error:
No method 'Add' with matching signature found for class 'Interface.2DF8D04D_5BFA_101B_BDE5_00AA0044DE52'.
Has anyone successfully used this function to add a custom property to an Excel workbook from MATLAB?
Related
enter image description here
select from list by index ${locator_var} ${inp_msge_type}
--getting error as expected string, int found
select from list by index ${locator_var} 7
-----not getting any error
${inp_msge_type}----contains 7 from DB query the result is stored in this variable, to avoid hard coding we need to do this
Is there any way to write
Do not add links to screenshots of code, or error messages, and format the code pieces accordingly - use the ` (tick) symbol to surround them.
The rant now behind us, your issue is that the keyword Select From List By Index expects the type of the index argument to be a string.
When you called it
Select From List By Index ${locator_var} 7
, that "7" is actually a string (though it looks like a number), because this is what the framework defaults to on any typed text. And so it works.
When you get the value from the DB, it is of the type that the DB stores it with; and probably the table schema says it is int. So now you pass an int to the keyword - and it fails.
The fix is simple - just cast (convert) the variable to a string type:
${inp_msge_type}= Convert To String ${inp_msge_type}
, and now you can call the keyword as you did before.
If I write this in the VBA editor:
Dim ws As Worksheet: set ws = ActiveSheet
ws.Columns(
IntelliSense shows me a seemingly unrelated tooltip:
_Default([RowIndex], [ColumnIndex])
The Worksheet.Columns property only accepts the index (column) number as far as I can see in the documentation.
So why am I asked for a RowIndex? Why does it refers to _Default (and what is it)?
The Worksheet.Columns property only accepts the index (column) number as far as I can see in the documentation.
Nowhere in the documentation does it say the Columns property takes a parameter, and indeed, it would be wrong to mention that, because it doesn't have any:
Like Worksheet.Rows, Worksheet.Columns yields a Range object. So when you "parameterize" it, what's really happening is this:
Set foo = ws.Columns.[_Default](value)
Any argument you provide, get interpreted as arguments to an implicit default member call against the Range object that was returned by the call to Columns.
You may have read somewhere that the default member of a Range is its Value - and that is not true. The default member of a Range is a hidden property named [_Default] (square brackets are required in VBA if you want to invoke it explicitly, because no legal VBA identifier can begin with an underscore), that takes two optional parameters:
When you read ("get") this default property without providing any arguments, this default property does get you the Range.Value (i.e. a single Variant value for a single cell, or a 2D Variant array for multiple cells). When you assign to this default property, you are assigning the Range.Value.
But when any arguments are provided when reading ("get") this default property, what you get is a call to the very standard Range.Item indexer property:
So what Columns does, is simply take your input range, and yield a Range object laid out in such a way that it can be accessed using a RowIndex argument - we can prove this using named arguments, which show that this code is illegal:
?Sheet1.Range("A1:C1").Columns.Item(ColumnIndex:=2).Address
>> "wrong number of arguments"
As is this equivalent code:
?Sheet1.Range("A1:C1").Columns(ColumnIndex:=2).Address
>> "error 1004"
Note that the _Default property yields a Variant, so the above .Address member call can only be resolved at run-time (and you don't get any intellisense for it, and the compiler will not flinch at any typo, even with Option Explicit specified - you will get error 438 at run-time though).
Best stick to safe early-bound land, and pull the returned object reference into a local variable:
Dim foo As Range
Set foo = ws.Columns(1)
Debug.Print foo.Address '<~ early-bound w/intellisense & compile-time validation
TL;DR: You're being prompted for a RowIndex argument because you are making a call (albeit an implicit one) to a hidden _Default property that accepts a RowIndex argument.
SlicersCaches.add and Slicers.Add gives error when I name the parameters but works fine without.
Error:
Set SC1 = ActiveWorkbook.SlicerCaches.Add(Source:=PivTable Sourcefield:="Dept")
Set SL1 = SC1.Slicers.Add(Slicerdestination:=PivSheet)
No Error:
Set SC1 = ActiveWorkbook.SlicerCaches.Add(PivTable, "Dept")
Set SL1 = SC1.Slicers.Add(PivSheet)
Is this a bug in the program?
There are no bugs in the program. When you call a Sub or Function procedure, you can supply arguments positionally, in the order they appear in the procedure's definition, or you can supply the arguments by name without regard to position.
Named arguments are especially useful when you are calling a procedure that has optional arguments. If you use named arguments, you don't have to include commas to denote missing positional arguments. Using named arguments makes it easier to keep track of which arguments you passed and which you omitted.
When you call a procedure with an optional argument, you can choose whether or not to specify the optional argument. If you don't specify the optional argument, the default value, if any, is used. If no default value is specified, the argument is it would be for any variable of the specified type.
Below are the complete definitions of the slicer functions with arguments (optional in square brackets):
Slicer.Add
Add(SlicerDestination, [Level], [Name], [Caption], [Top], [Left], [Width], [Height]) As Slicer
SlicerCache.Add
Add(Source, SourceField, [Name]) As SlicerCache
I has many user define function with arguments and without. I use CUdfHelper from this article http://www.jkp-ads.com/articles/RegisterUDF00.asp for register function.
Registered function ask arguments for arguments, even if they are not.
Example my fuction without arguments:
Public Function getProjects()
getProjects = Utils.execute("getProjects", "getWSEntitiesData")
End Function
On MyFunction.c
#include <windows.h>
#define DLL_EXPORT __declspec(dllexport)
DLL_EXPORT void getProjects() {
return;
}
compile on MyFunction.dll
I register the function with these parameters.
SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects", "", 1, "MyFunctionCategory", "", "", "Return list projects")
If I register as
SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects",, 1, "MyFunctionCategory", "", "", "Return list projects")
Function argument dialog is displayed all the same.
If I register as
SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects",, 1, "MyFunctionCategory")
Function argument dialog isn't displayed, but the description is no longer available.
REGISTER() Arguments
Path and name of the dll
Name of the function you wish to call
Type string
The name you want to use in Excel cells
A list of arguments to use in the function wizard
The Macro type (2 for a function, 2 for a command)
Which function wizard category to add the function to
Short cut text if the function being registered is a command
Path to help file
Function help to show in the function wizard
11-30 onwards help text for each argument in the function wizard.
I think the problem is in the arguments, as by default it is set to an empty string, and I can not figure out how to change the parameters to the function.
On CUdfHelper
' structure definition
Private Type REGARG
sDllName As String
sDllProc As String
sArgType As String
sFunText As String
**sArgText As String**
iMacType As Integer
vCatName As Variant
sKeyText As String
sHlpPath As String
**sFunHelp As String**
aArgHelp(1 To 20) As String
End Type
How to correctly set the parameters so that the window does not appear, and stores the description?
If register function with ExecuteExcel4Macro and set Function Description. In an XLL add-in, however, you may run into a bug in the Excel API. The bug shows itself if a parameterless function is mentioned in an ADXExcelFunctionDescriptor that has a non-empty string in the Description property. If this is the case, you'll get another version of the Function Arguments dialog.
That is, to bypass that issue, you need to leave the ADXExcelFunctionDescriptor.Description property empty.
Find on https://www.add-in-express.com/docs/net-excel-udf-tips.php
I need to pass an object type value to a procedures, which read from a text file (String fromat).
'param node- Object type
'param txtvalue - String
Function setTexttoElement(nodename, txtvalue)
nodename.Text = txtvalue
End Function
Method is finely works when passing following values
setTexttoElement myElement, abc
But when reading a file it's take String format. So I need to convert first value as Object
"myElement", "abc"
How to solve this?
You will need to create a reference dictionary to convert the text string to an object effectively, as there is no way for vbscript to know what type of object you are passing to the function. For more information: click here.