ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   .bat file in Excel with parameters (https://www.excelbanter.com/excel-discussion-misc-queries/146295-bat-file-excel-parameters.html)

Ashly A K

.bat file in Excel with parameters
 
hi!

I am looking for a VBA (or anything!!! yes..i am very desperate) which will
enable me to run a .BAT file with parameters from Excel.

ie: if i have a .BAT file, which will ping a IP Address
..BAT will look like

@Echo off
ping %1

So, when i run from the command prompt, i could run as "filename.bat
192.168.0.10" - which will ping the IP Address.

I want to achieve this thru an Excel File. Ie : there will be IP address
in a Colum, and as users click on that, the system shoud run the .bat file,
by taking the IP address given.

I even tried to call this as a hyper link, but was not able to pass the
parameters.

Could any one PLEASE.... help me ?

-Ashly


Gary''s Student

.bat file in Excel with parameters
 
Here is a .bat file called testfile.bat:

echo %1
pause

Here is a piece of VBA that calls it with a parameter:

Sub parm_it()
ChDir ("C:\")
x = Shell("cmd.exe /c testfile.bat hello", 1)
End Sub

Upon selecting a cell, your macro would
1. get the ping address
2. do the Shell with hello replaced
--
Gary''s Student - gsnu200728


"Ashly A K" wrote:

hi!

I am looking for a VBA (or anything!!! yes..i am very desperate) which will
enable me to run a .BAT file with parameters from Excel.

ie: if i have a .BAT file, which will ping a IP Address
.BAT will look like

@Echo off
ping %1

So, when i run from the command prompt, i could run as "filename.bat
192.168.0.10" - which will ping the IP Address.

I want to achieve this thru an Excel File. Ie : there will be IP address
in a Colum, and as users click on that, the system shoud run the .bat file,
by taking the IP address given.

I even tried to call this as a hyper link, but was not able to pass the
parameters.

Could any one PLEASE.... help me ?

-Ashly


Ashly A K[_2_]

.bat file in Excel with parameters
 
hi!!

Thanks a TON!!!
One more question, insted of harcoding "hello" in the VBA, can i make it
read from a cell ?

-Ashly

"Gary''s Student" wrote:

Here is a .bat file called testfile.bat:

echo %1
pause

Here is a piece of VBA that calls it with a parameter:

Sub parm_it()
ChDir ("C:\")
x = Shell("cmd.exe /c testfile.bat hello", 1)
End Sub

Upon selecting a cell, your macro would
1. get the ping address
2. do the Shell with hello replaced
--
Gary''s Student - gsnu200728


"Ashly A K" wrote:

hi!

I am looking for a VBA (or anything!!! yes..i am very desperate) which will
enable me to run a .BAT file with parameters from Excel.

ie: if i have a .BAT file, which will ping a IP Address
.BAT will look like

@Echo off
ping %1

So, when i run from the command prompt, i could run as "filename.bat
192.168.0.10" - which will ping the IP Address.

I want to achieve this thru an Excel File. Ie : there will be IP address
in a Colum, and as users click on that, the system shoud run the .bat file,
by taking the IP address given.

I even tried to call this as a hyper link, but was not able to pass the
parameters.

Could any one PLEASE.... help me ?

-Ashly


Roger Govier

.bat file in Excel with parameters
 
Hi

Just amend Gary's code
x = Shell("cmd.exe /c testfile.bat " & Range("A1"), 1)

--
Regards

Roger Govier


"Ashly A K" wrote in message
...
hi!!

Thanks a TON!!!
One more question, insted of harcoding "hello" in the VBA, can i make
it
read from a cell ?

-Ashly

"Gary''s Student" wrote:

Here is a .bat file called testfile.bat:

echo %1
pause

Here is a piece of VBA that calls it with a parameter:

Sub parm_it()
ChDir ("C:\")
x = Shell("cmd.exe /c testfile.bat hello", 1)
End Sub

Upon selecting a cell, your macro would
1. get the ping address
2. do the Shell with hello replaced
--
Gary''s Student - gsnu200728


"Ashly A K" wrote:

hi!

I am looking for a VBA (or anything!!! yes..i am very desperate)
which will
enable me to run a .BAT file with parameters from Excel.

ie: if i have a .BAT file, which will ping a IP Address
.BAT will look like

@Echo off
ping %1

So, when i run from the command prompt, i could run as
"filename.bat
192.168.0.10" - which will ping the IP Address.

I want to achieve this thru an Excel File. Ie : there will be IP
address
in a Colum, and as users click on that, the system shoud run the
.bat file,
by taking the IP address given.

I even tried to call this as a hyper link, but was not able to pass
the
parameters.

Could any one PLEASE.... help me ?

-Ashly




Ashly A K[_2_]

.bat file in Excel with parameters
 
hi! Thanks!!
I tried it. Below is my code :

Sub parm_it()
ChDir ("C:\")
x = Shell("cmd.exe /c a.bat" & Range("A1"), 1)
End Sub

and my .bat file looks like :
@echo off
pause
ping %1
pause

This is a test .bat file, i put 2 "pause" in between to see what is happening.

Well, my Excel Sheet is like below :
192.168.0.10
10.15.40.15
123.58.48.10
And all are in "A1","A2", and "A3" cells. So, when the user click on A1,
the system should ping 192.168.0.10.
I tried the modifiction you told, but it is not working. A DOS window comes
and dispaers. I can't even read what it is. If the .BAT file is getting
executed, it should come and pasue.

Thanks a LOT for your great helping hand.

-Regards,
Ashly A K



"Roger Govier" wrote:

Hi

Just amend Gary's code
x = Shell("cmd.exe /c testfile.bat " & Range("A1"), 1)

--
Regards

Roger Govier


"Ashly A K" wrote in message
...
hi!!

Thanks a TON!!!
One more question, insted of harcoding "hello" in the VBA, can i make
it
read from a cell ?

-Ashly

"Gary''s Student" wrote:

Here is a .bat file called testfile.bat:

echo %1
pause

Here is a piece of VBA that calls it with a parameter:

Sub parm_it()
ChDir ("C:\")
x = Shell("cmd.exe /c testfile.bat hello", 1)
End Sub

Upon selecting a cell, your macro would
1. get the ping address
2. do the Shell with hello replaced
--
Gary''s Student - gsnu200728


"Ashly A K" wrote:

hi!

I am looking for a VBA (or anything!!! yes..i am very desperate)
which will
enable me to run a .BAT file with parameters from Excel.

ie: if i have a .BAT file, which will ping a IP Address
.BAT will look like

@Echo off
ping %1

So, when i run from the command prompt, i could run as
"filename.bat
192.168.0.10" - which will ping the IP Address.

I want to achieve this thru an Excel File. Ie : there will be IP
address
in a Colum, and as users click on that, the system shoud run the
.bat file,
by taking the IP address given.

I even tried to call this as a hyper link, but was not able to pass
the
parameters.

Could any one PLEASE.... help me ?

-Ashly





Roger Govier

.bat file in Excel with parameters
 
Hi Ashly

x = Shell("cmd.exe /c a.bat" & Range("A1"), 1)

You deleted the space after bat and before the double quote
try
x = Shell("cmd.exe /c a.bat " & Range("A1"), 1)


--
Regards

Roger Govier


"Ashly A K" wrote in message
...
hi! Thanks!!
I tried it. Below is my code :

Sub parm_it()
ChDir ("C:\")
x = Shell("cmd.exe /c a.bat" & Range("A1"), 1)
End Sub

and my .bat file looks like :
@echo off
pause
ping %1
pause

This is a test .bat file, i put 2 "pause" in between to see what is
happening.

Well, my Excel Sheet is like below :
192.168.0.10
10.15.40.15
123.58.48.10
And all are in "A1","A2", and "A3" cells. So, when the user click on
A1,
the system should ping 192.168.0.10.
I tried the modifiction you told, but it is not working. A DOS window
comes
and dispaers. I can't even read what it is. If the .BAT file is
getting
executed, it should come and pasue.

Thanks a LOT for your great helping hand.

-Regards,
Ashly A K



"Roger Govier" wrote:

Hi

Just amend Gary's code
x = Shell("cmd.exe /c testfile.bat " & Range("A1"), 1)

--
Regards

Roger Govier


"Ashly A K" wrote in message
...
hi!!

Thanks a TON!!!
One more question, insted of harcoding "hello" in the VBA, can i
make
it
read from a cell ?

-Ashly

"Gary''s Student" wrote:

Here is a .bat file called testfile.bat:

echo %1
pause

Here is a piece of VBA that calls it with a parameter:

Sub parm_it()
ChDir ("C:\")
x = Shell("cmd.exe /c testfile.bat hello", 1)
End Sub

Upon selecting a cell, your macro would
1. get the ping address
2. do the Shell with hello replaced
--
Gary''s Student - gsnu200728


"Ashly A K" wrote:

hi!

I am looking for a VBA (or anything!!! yes..i am very desperate)
which will
enable me to run a .BAT file with parameters from Excel.

ie: if i have a .BAT file, which will ping a IP Address
.BAT will look like

@Echo off
ping %1

So, when i run from the command prompt, i could run as
"filename.bat
192.168.0.10" - which will ping the IP Address.

I want to achieve this thru an Excel File. Ie : there will be
IP
address
in a Colum, and as users click on that, the system shoud run the
.bat file,
by taking the IP address given.

I even tried to call this as a hyper link, but was not able to
pass
the
parameters.

Could any one PLEASE.... help me ?

-Ashly








All times are GMT +1. The time now is 12:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com