Do you know how to execute Excel macro module in JSCRIPT? - excel

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.

Related

Matlab error - Attempt to extract field 'Workbooks' from 'mxArray'

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.

Error accessing external function select - Excel sheet in powerbuilder

This is the my script.
Im getting error in select method.
Please help.
Thanks in advance
OLEObject xlApp,xls_1,xls_2
integer li_rc
string ls_filepath = "D:\backup\"
xlApp = Create OLEObject
li_rc = xlApp.ConnectToNewObject( "Excel.Application" )
if li_rc < 0 then
MessageBox("Connect to Excel Failed !",string(li_rc))
Return -1
end if
xlApp.Application.Workbooks.Open(ls_filepath+'\test1.xls')
xlApp.Application.Workbooks.Open(ls_filepath+'\test2.xls')
xls_1 = xlApp.Application.Workbooks[1].Worksheets[1]
xls_2 = xlApp.Application.Workbooks[2].Worksheets[1]
xls_2.activate()
xls_1 .activate()
xls_2.rows("1:8").copy()
xls_1 .Rows("1:8").Select()
xls_1 .paste()
xlApp.Application.workbooks[1].SaveAs(ls_filepath+"\test3.xls")
xlApp.Application.WorkBooks.close()
xlApp.Application.WorkBooks.Application.quit()
destroy xlApp
destroy xls_1
destroy xls_2
Return 1
Welcome to the wonderful world of dynamic objects (weak typing)
These kinds of things require more conscientious development techniques particularly checking the type of object, property, function or whatever your dot nation has navigated you in the neighborhood of.
But some OLE objects are weak on functions to interrogate the entire object model of a dynamic object forcing you to rely heavily on Microsoft OLE documentation which is boring and often version specific. I think your issue would be easier seen by a VBA and/or Visual Basic Scripting or Excel OLE expert.
But in the name of a PowerBuilder solution. It sometimes helps to wrap operations on dynamic objects in TRY..CATCH..FINALLY clause and then add your own code to handle the various OLE Exceptions and prevent PB from crashing each time your dot nation doesn't match what was expected.

Wanted: DXL code to export OLE object to Excel and specify "Placement" parameter

I have working DXL code to export a DOORS module to Excel, including sizing pictures and placing them over the desired cell. (Slightly modified version of GalacticSolutions script ). The default export so far as I can tell applies the parameter "Move but do not size with cell." I'd like to specify "Move and size with cell." This is easy enough to do with an Excel VB macro after the export, but I'd like to avoid that step. I'm hoping there's some Oleput() string that will do this, but can't figure it out.
I just worked through this today.
In the script, I added a new constant under the Excel VBA Properties section.
const string cExcelPropertyPlacement = "Placement"
Created a new little subroutine:
void excelShapeRangePlacement( OleAutoObj objExcelShapeRange, int OlePlacement ) {
oleResult( olePut( objExcelShapeRange, cExcelPropertyPlacement, OlePlacement ) )
}
Then called the new routine a the end of the "excelSizeShape" subroutine.
// values: 1-MoveandSize, 2-Move, 3-Freefloating
excelShapeRangePlacement( objExcelShapeRange, 1 )
This should set the value for the OLEs output into Excel..

programming for excel with foxpro (or any suggestions)

I have a macro in excel that works.
Sub jim()
Range("$A$1").CurrentRegion.Select
Selection.RowHeight = 13
Selection.Font.Bold = True
…etc.
If I open a csv and run this macro it selects the seen data and then later does stuff to it.
So I made a foxpro program to do the same.
When I try to run in foxpro, I get a variable not found error.
local oExcel, oSheet
oExcel = CreateObject([Excel.Application])
oExcel.Visible = .T.
k:\wellcarestuff\All Data Files\"+ALLTRIM(xlfiles(1,1))
osheet = oexcel.workbooks.open("k:\wellcarestuff\all data files\20131210_CT_TransportationAddresses.csv") <<<=== it opens and shows the sheet here
Range("$A$1").CurrentRegion.Select <<<?=== get an error here?
Is the var it wants the current osheet?
On the line with the path, it looks like you are missing the beginning quote marks so it things that k:... is a variable. Should be:
"k:\wellcarestuff\All Data Files\"+ALLTRIM(xlfiles(1,1))
Try that and see if it works.

How to save an Excel sheet as PDF through MATLAB?

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.

Resources