How to call a macro script in qtp and to run that macro script in excel - macros

I have a created a macro script by recording in excel. Now I need to run this macro script in newly opened excel via QTP (Vb script) . Can anyone suggest me , what call function can be used in qtp to run this macro script in excel?
my macro script is
Sub csi()
' csi Macro
' Keyboard Shortcut: Ctrl+c
ActiveCell.FormulaR1C1 = "test test test "
Range("B1").Select
End Sub

As explained as an answer to a similar question it is not very difficult:
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "test.xls!csi"
or
objExcel.Application.Run "test.xls!sheet1.csi"
Depending if the macro resides in a module or in a sheet.

Related

How to convert powershell onliner to PS1

I have a powershell one liner that would like to transform on a PS1 file
This question is pretty basic but how do I convert apowershell one liner to PS1?
Thanks
There are a few steps to do this:
Open notepad.
Copy and paste the powershell script into notepad. Now if the one-liner has multiple lines using ; separate them by using enter. You can expand The for, if, while, try blocks like this:
try
{
Anything
}
You can also make the script accept args using $args automatic variable. $args[0], $args[1] .. $args[n] parameters and so on.
Select file menu and save as dialog.
Enter the name of powershell script with extension .ps1 (Example: foo.ps1).
Choose "All files" in the drop down menu.
Click save button. Here you go!

MATLAB System Command "Press Enter to Exit"

I am trying to write a MATLAB script that would call and run an external program and then proceed with other MATLAB commands.
tic %Start stopwatch
system('MyProgram.exe') %Call and run my program
toc %End stopwatch
However, this program "MyProgram.exe" requires me to "Press Enter to Exit." How to make my MATLAB script pass "Enter" to proceed? Like How to pass "Enter" as an input of my program at the end of execution? Or how to do this in general ?
On UNIX, you can use
system('MyProgram < /dev/null').
as suggested in the Matlab documentation:
To disable stdin and type-ahead redirection, include the formatted
text < /dev/null in the call to the invoked command.
The Windows equivalent is (based on this post):
system('MyProgram.exe < NUL')
When a console program needs to take input one time from the user and there is no built-in way to do so (like passing it in as an argument), that input can be echoed and piped to the program. This can also be used to press Enter (again, once) by piping a blank line.
echo.|program.exe
While traditionally a blank line is generated with echo by using the command echo., this can fail if the current directory contains a file called echo that has no extension. To get around this, you can use a ( instead of a ..
echo(|program.exe

Matlab - Path to the Current Script

Under any two years recent version of MATLAB, I am looking for the path of the current script being executed (ref.1, 2, 3, 4, 5),
Let's say, for a script through any of the following user procedures, in general, when a user runs a script:
The "Run", "Run and Advance", "Run Section" or "Run and Time" menu buttons,
The "Evaluate Selection" or "Evaluate Current Selection" contextual menus from the Editor,
The F9 or Ctrl+Enter keyboard shortcuts from the Editor.
User procedures that could not be accepted by the solution, because there would be no associated script, are:
Executing a piece of code directly in the command line,
The contextual or keyboard shortcuts for executing a code from a Matlab interface or windows outside the Editor -Document, Browser, Help.
User procedures out of the scope of the question related to functions, which could be solved easily through any of the following indicated solutions, is:
Calling the script as a function from the command line, from another script or from a function.
This is not for a function, which is trivially done through any of the following alternatives:
mfilename
mfilename('fullpath')
which(mfilename)
which('mfilename')
S = dbstack('-completenames');S(1).file
[folder,name,ext] = fileparts(which('object'))
And this is of course not the same that requesting the current folder through:
cd
pwd
edit I misunderstood the question initially...
So with hopefully a bit better understanding you could try and utilise:
matlab.desktop.editor.getActiveFilename
to get the current active file in the editor -> which should give the current script...
Note: this is an undocumented function which may change between releases -> it gives me the active filename in r2015b.

Lua (Command Line) remain open after execution

I have searched far and wide for this but I cannot seem to find it. Is there any way to execute a Lua script via double clicking it (to execute it in Lua (Command Line)) and keep it open after execution?
For example:
print("Hello World")
This code compiles and runs, however if I double click on hello.luait runs and closes immediately without leaving my text on screen. I want something more like this, but without having to go to Command Prompt, changing directory a bunch of times, typing lua file.lua, etc.:
Add io.read() at the end of your script.
The easiest way would be to just add a 'pause' at the end of your script:
print 'Hello World'
os.execute 'pause'

How can I run a Perl script through an ActiveX Control within Excel?

I want to run a Perl script at the click of a button inside an Excel spreadsheet.
As the button is assigned to execute a VB macro, the macro should effectively execute the program.
As my first ever VB script, this is what I came up with, which throws up an irritating Run-time error '424': Object required error.
Sub RunPerlScript()
System.Diagnostics.process.Start ("perlscript.pl")
End Sub
How can I get this script to do what I want it to do?
I didn't write this snippet, but it would seem to be a good answer to your question.
From the article "How to execute a perl script from VBA":
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub RunPerl()
MsgBox ("Start of macro")
Dim oWsc As Object
Set oWsc = CreateObject("WScript.Shell")
Dim oExec As Object
Set oExec = oWsc.Exec("perl C:\temp\myperl.pl StartParam")
While oExec.Status <> 1 ' Wait for process
Sleep 1000
Wend
MsgBox ("STDOUT" + oExec.StdOut.ReadAll())
MsgBox ("STDERR" + oExec.StdErr.ReadAll())
Set oWsc = Nothing
MsgBox ("End of macro")
End Sub
You might need to install ActivePerl first
You cannot use .NET classes in a VBA macro.
Use the VBA Shell function.
Shell "p:\ath\to\perlscript.pl"
The documentation:
Shell Function
Runs an executable program and returns
a Variant (Double) representing the
program's task ID if successful,
otherwise it returns zero.
Syntax
Shell(pathname[,windowstyle])
The Shell function syntax has these
named arguments:
Part Description pathname Required;
Variant (String). Name of the program
to execute and any required arguments
or command-line switches; may include
directory or folder and drive. On the
Macintosh, you can use the MacID
function to specify an application's
signature instead of its name. The
following example uses the signature
for Microsoft Word: Shell
MacID("MSWD") windowstyle Optional.
Variant (Integer) corresponding to the
style of the window in which the
program is to be run. If windowstyle
is omitted, the program is started
minimized with focus. On the Macintosh
(System 7.0 or later), windowstyle
only determines whether or not the
application gets the focus when it is
run.
The windowstyle named argument has
these values:
Constant Value Description vbHide 0
Window is hidden and focus is passed
to the hidden window. The vbHide
constant is not applicable on
Macintosh platforms. vbNormalFocus 1
Window has focus and is restored to
its original size and position.
vbMinimizedFocus 2 Window is displayed
as an icon with focus.
vbMaximizedFocus 3 Window is maximized
with focus. vbNormalNoFocus 4 Window
is restored to its most recent size
and position. The currently active
window remains active.
vbMinimizedNoFocus 6 Window is
displayed as an icon. The currently
active window remains active.
ActiveState's PDK has PerlCtrl which lets you package a perl script as an ActiveX control. It gathers up your script and all dependencies into a tidy DLL.