I try to use Simulink MATLAB Function block to run Excel macro. Below is my code:
function duty = fcn()
duty = zeros(1,1);
coder.extrinsic('actxserver')
excel = actxserver('Excel.Application')
excel.Workbooks.Open('D:\pso.xlsm')
excel.Run('Sheet1.run_pso');
excel.Quit;
end
However, error come out as:
Attempt to extract field 'Workbooks' from 'mxArray'.
Anyone please help me, thank you.
Related
Do you know how to execute Excel macro module in JSCRIPT(not JAVASCRIPT and VBSCRIPT)?
Double-clicking the jscript file causes the Excel macro module to run.
But it does not work.
I wrote jscript codes like this.
var ExcelApp = new ActiveXObject( "Excel.Application" );
ExcelApp.Visible = true
WScript.Sleep( 3000 );
var ebook = ExcelApp.Workbooks.Open("C:\\Users\\※※\\Desktop\\folder\\file.xlsm" );
WScript.Sleep( 1000 );
'The following line always caused the error.
'Although JSCRIPT opens Excel, but does not run the macro module.
ExcelApp.Run( "C:\\Users\\※※\\Desktop\\folder\\file.xlsm!Hello" );'This was no good.
'ExcelApp.Run( "file.xlsm!Hello" );'This was no good,too.
'ExcelApp.Run( "Hello" );'This was no good,too.
ebook.Close();
WScript.Sleep( 1000 );
ExcelApp.Quit();
ExcelApp = null;
I wrote Excel macro module codes like this in "file.xlsm".
Sub Hello()
MsgBox ("Hello!")
End Sub
I know it's feasible with VBScript or other languages, but I'd like to do it with jscript somehow.
I'm in trouble because there are no people around who understand JSCRIPT, I can't find the JSCRIPT book when I go to a large bookstore near my house in Japan, and even if I look it up on the Internet, there is no suitable information.
I wish I could give up, but if I could, I would like to get it done.
If anyone knows, please let me know. Thanks.
I did it.
ExcelApp.Run("Hello.Hello").'ExcelApp.Run("modulename.procedurename")
This runs.Thanks.
The code below has worked until my most recent update to it in. It still does work, but for some reason, it errors when opening it on a new PC if you have to click Enabling Editing. If you Enable Editing, end the routine, and close the spreadsheet, it works from there. I am just trying to understand what might be causing the hiccup on the initial open after Enabling Editing.
The code (please note that "Mnger_Tags" is a named group defined in the spreadsheet):
Dim Mnger As Variant, MngerCheck As String
Application.DisplayAlerts = False
'Determine User/Manager
Mnger = Application.Transpose(Range("Mnger_Tags").Value)
MngerCheck = LCase(Environ("UserName"))
If IsInArray(MngerCheck, Mnger) Then
frmMngerCheck.Show
MngerCheck = frmMngerCheck.MngerCheck
Unload frmMngerCheck
End If
The Error:
Takes place on line "Mnger = Application.Transpose(Range("Mnger_Tags").Value)"
Run-time error '1004':
Method 'Range' of object '_Global' failed
The goal:
The first line of code is meant to take whatever names are listed in that named range (Mnger_Tags) and create the array Mnger.
The code will then check if any value in the array Mnger match the UserName (MngerCheck).
I hope this is clear enough. This is my first post. Thank you all in advance.
I want to perform a validation on a column. The validation is that X should start with 0.
When data is entered and when closing the excel sheet, it should throw an error message saying the data is incorrect and it should not allow me to close until and unless I correct the data.
I have put the code in Before Close. It is showing the error message if data is incorrect, but closing before we change the incorrect data.
Also tried with Before save. It is same behaviour found.
Any help or suggestion is appreciated.
Thanks,
Jaya Vignesh Kannan
I believe that the Workbook_Before_Close macro has a 'Cancel' parameter. You could then do something like this:
Dim isValid As Boolean
' Calculate isValid however you'd like
If Not isValid Then
MsgBox "This is my invalid message!"
Cancel = True 'Cancel workbook close
End If
I am using the following code:
hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(sprintf('%s','C:\test.xlsx'));
hWorksheet = hWorkbook.Sheets.Item(1);
hRange = hWorksheet.Range('A1:O10');
hRange.ExportAsFixedFormat('xlTypePDF','test_out.pdf');
The Excel ActiveX server allows me to do the usual stuff, but the last line doesn't do anything. Neither does it throw any error.
Does anyone know how to do this?
I think you need to use hWorkbook.ExportAsFixedFormat, not hRange.ExportAsFixedFormat.
Also, you'll need to specify the full path to the output file as C:\test_out.pdf.
I want to select some values through VBA in Pivot Table which is linked to OLAP Cube.
As I know such modification can be realised by typing:
ActiveSheet.PivotTables("PivotTable1").PivotFields("[parameter].[parameter]").VisibleItemsList = Array("value1","value2","value3")
Since get list of parameters from cells in Excel sheet, I wrote simple function which - In mentioned example - returns:
""value1","value2","value3""
I can't use such string as parameter for Array function (as it recognize it as one string), so I've tried to convert it to Array of Variant, typing above code:
Dim tableVar() As Variant
myVar = Replace(myVar, Chr(34), "")
myVar = Split(myVar, ",")
lowerB =LBound(myVar)
upperB = UBound(myVar)
ReDim tablica(lowerB To upperB)
For i = lowerB To upperB
tableVar(i) = myVar(i)
Next i
Unfortunately it changes nothing - when I'm calling:
ActiveSheet.PivotTables("PivotTable1").PivotFields("[parameter].[parameter]").VisibleItemsList = tableVar
I'm still receiving an error message.
Could you help me, please?
you have a typo in your code, daty should say myVar.
(Either that or we're missing more details)
Stupid thing, but error message is simply correct - there's no such items in Cube:
Run-time error '1004': The item could not be found in the OLAP Cube
I gave incorrect parameter here:
ActiveSheet.PivotTables("PivotTable1").PivotFields("[parameter].[parameter]").VisibleItemsList = tableVar
My code was unnecessary complicated - sorry for wasting your time.
Now my problem will be - how to check if specific dimensions or whole Cube exist...
Thanks once more for help.