Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Return Information from Shell Command

Hi All,

I have a dos command that lists the location of a config file associated
with a program.

This works fine from a dos prompt but can I use the Shell command in such a
way that the location of the config file can be returned into VBA?

Something like Var = Shell("Getconfig") (I am aware that doing this merely
would set Var = process thread associated with shell)

Thanks

Andi



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Return Information from Shell Command

There might well be a more elegant solution (and indeed this might not
work) but you could try using "" to output the returned data to a file
rather than the screen. e.g.

Function fcnGetConfigLocation() as string

DIm var as long
Dim myPath as string
DIm F as integer

Var = Shell("Getconfig c:\temp.txt")

'assuming file just contains one path

F= Freefile
open "c:\temp.txt" for input as #F
input #F, mypath
close #F

kill "c:\temp.txt"

'check path exists
myPath = trim(mypath)
if dir(mypath) < "" then _
fcnGetConfigLocation = myPath

End Function


HTH,
Gareth

Andibevan wrote:
Hi All,

I have a dos command that lists the location of a config file associated
with a program.

This works fine from a dos prompt but can I use the Shell command in such a
way that the location of the config file can be returned into VBA?

Something like Var = Shell("Getconfig") (I am aware that doing this merely
would set Var = process thread associated with shell)

Thanks

Andi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Return Information from Shell Command

Hi Gareth - Thanks for the solution but I am having some problems.

Can you try and see if you can get it to work using "Dir C:\test.txt" as I
am having problems getting shell commands to write to a file.

All I need to know is how to get the bit working that actually creates the
file.

Ta

Andi

"Gareth" wrote in message
...
There might well be a more elegant solution (and indeed this might not
work) but you could try using "" to output the returned data to a file
rather than the screen. e.g.

Function fcnGetConfigLocation() as string

DIm var as long
Dim myPath as string
DIm F as integer

Var = Shell("Getconfig c:\temp.txt")

'assuming file just contains one path

F= Freefile
open "c:\temp.txt" for input as #F
input #F, mypath
close #F

kill "c:\temp.txt"

'check path exists
myPath = trim(mypath)
if dir(mypath) < "" then _
fcnGetConfigLocation = myPath

End Function


HTH,
Gareth

Andibevan wrote:
Hi All,

I have a dos command that lists the location of a config file associated
with a program.

This works fine from a dos prompt but can I use the Shell command in

such a
way that the location of the config file can be returned into VBA?

Something like Var = Shell("Getconfig") (I am aware that doing this

merely
would set Var = process thread associated with shell)

Thanks

Andi





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Return Information from Shell Command

Try something like this:

Shell Environ("comspec") _
& " /c dir c:\temp " _
& " c:\temp.txt", vbHide

It should work.

(I write "should" work - it does work, I tested it! It's not my code, it
was posted by someone called Rick Rothstein, clearly a very nice man, in
a VB NG back in 1999.)

Tara


Andibevan wrote:
Hi Gareth - Thanks for the solution but I am having some problems.

Can you try and see if you can get it to work using "Dir C:\test.txt" as I
am having problems getting shell commands to write to a file.

All I need to know is how to get the bit working that actually creates the
file.

Ta

Andi

"Gareth" wrote in message
...

There might well be a more elegant solution (and indeed this might not
work) but you could try using "" to output the returned data to a file
rather than the screen. e.g.

Function fcnGetConfigLocation() as string

DIm var as long
Dim myPath as string
DIm F as integer

Var = Shell("Getconfig c:\temp.txt")

'assuming file just contains one path

F= Freefile
open "c:\temp.txt" for input as #F
input #F, mypath
close #F

kill "c:\temp.txt"

'check path exists
myPath = trim(mypath)
if dir(mypath) < "" then _
fcnGetConfigLocation = myPath

End Function


HTH,
Gareth

Andibevan wrote:

Hi All,

I have a dos command that lists the location of a config file associated
with a program.

This works fine from a dos prompt but can I use the Shell command in


such a

way that the location of the config file can be returned into VBA?

Something like Var = Shell("Getconfig") (I am aware that doing this


merely

would set Var = process thread associated with shell)

Thanks

Andi






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Return Information from Shell Command

Haven't had time to test it yet - but thanks for the input.

I don't suppose you've got a URL with a bit more info have you?

Mainly what the comspec and the /c mean?

Thanks

Andi


"Gareth" wrote in message
...
Try something like this:

Shell Environ("comspec") _
& " /c dir c:\temp " _
& " c:\temp.txt", vbHide

It should work.

(I write "should" work - it does work, I tested it! It's not my code, it
was posted by someone called Rick Rothstein, clearly a very nice man, in
a VB NG back in 1999.)

Tara


Andibevan wrote:
Hi Gareth - Thanks for the solution but I am having some problems.

Can you try and see if you can get it to work using "Dir C:\test.txt"

as I
am having problems getting shell commands to write to a file.

All I need to know is how to get the bit working that actually creates

the
file.

Ta

Andi

"Gareth" wrote in message
...

There might well be a more elegant solution (and indeed this might not
work) but you could try using "" to output the returned data to a file
rather than the screen. e.g.

Function fcnGetConfigLocation() as string

DIm var as long
Dim myPath as string
DIm F as integer

Var = Shell("Getconfig c:\temp.txt")

'assuming file just contains one path

F= Freefile
open "c:\temp.txt" for input as #F
input #F, mypath
close #F

kill "c:\temp.txt"

'check path exists
myPath = trim(mypath)
if dir(mypath) < "" then _
fcnGetConfigLocation = myPath

End Function


HTH,
Gareth

Andibevan wrote:

Hi All,

I have a dos command that lists the location of a config file

associated
with a program.

This works fine from a dos prompt but can I use the Shell command in


such a

way that the location of the config file can be returned into VBA?

Something like Var = Shell("Getconfig") (I am aware that doing this


merely

would set Var = process thread associated with shell)

Thanks

Andi










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Return Information from Shell Command

'Fraid not. Here's the URL I got it from:

http://groups.google.com/group/micro... 4b11224427f2a

G

Andibevan wrote:
Haven't had time to test it yet - but thanks for the input.

I don't suppose you've got a URL with a bit more info have you?

Mainly what the comspec and the /c mean?

Thanks

Andi


"Gareth" wrote in message
...

Try something like this:

Shell Environ("comspec") _
& " /c dir c:\temp " _
& " c:\temp.txt", vbHide

It should work.

(I write "should" work - it does work, I tested it! It's not my code, it
was posted by someone called Rick Rothstein, clearly a very nice man, in
a VB NG back in 1999.)

Tara


Andibevan wrote:

Hi Gareth - Thanks for the solution but I am having some problems.

Can you try and see if you can get it to work using "Dir C:\test.txt"


as I

am having problems getting shell commands to write to a file.

All I need to know is how to get the bit working that actually creates


the

file.

Ta

Andi

"Gareth" wrote in message
...


There might well be a more elegant solution (and indeed this might not
work) but you could try using "" to output the returned data to a file
rather than the screen. e.g.

Function fcnGetConfigLocation() as string

DIm var as long
Dim myPath as string
DIm F as integer

Var = Shell("Getconfig c:\temp.txt")

'assuming file just contains one path

F= Freefile
open "c:\temp.txt" for input as #F
input #F, mypath
close #F

kill "c:\temp.txt"

'check path exists
myPath = trim(mypath)
if dir(mypath) < "" then _
fcnGetConfigLocation = myPath

End Function


HTH,
Gareth

Andibevan wrote:


Hi All,

I have a dos command that lists the location of a config file


associated

with a program.

This works fine from a dos prompt but can I use the Shell command in

such a


way that the location of the config file can be returned into VBA?

Something like Var = Shell("Getconfig") (I am aware that doing this

merely


would set Var = process thread associated with shell)

Thanks

Andi








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Return Information from Shell Command

Nice one - Thanks

"Gareth" wrote in message
...
'Fraid not. Here's the URL I got it from:


http://groups.google.com/group/micro... 4b11224427f2a

G

Andibevan wrote:
Haven't had time to test it yet - but thanks for the input.

I don't suppose you've got a URL with a bit more info have you?

Mainly what the comspec and the /c mean?

Thanks

Andi


"Gareth" wrote in message
...

Try something like this:

Shell Environ("comspec") _
& " /c dir c:\temp " _
& " c:\temp.txt", vbHide

It should work.

(I write "should" work - it does work, I tested it! It's not my code, it
was posted by someone called Rick Rothstein, clearly a very nice man, in
a VB NG back in 1999.)

Tara


Andibevan wrote:

Hi Gareth - Thanks for the solution but I am having some problems.

Can you try and see if you can get it to work using "Dir C:\test.txt"


as I

am having problems getting shell commands to write to a file.

All I need to know is how to get the bit working that actually creates


the

file.

Ta

Andi

"Gareth" wrote in message
...


There might well be a more elegant solution (and indeed this might not
work) but you could try using "" to output the returned data to a

file
rather than the screen. e.g.

Function fcnGetConfigLocation() as string

DIm var as long
Dim myPath as string
DIm F as integer

Var = Shell("Getconfig c:\temp.txt")

'assuming file just contains one path

F= Freefile
open "c:\temp.txt" for input as #F
input #F, mypath
close #F

kill "c:\temp.txt"

'check path exists
myPath = trim(mypath)
if dir(mypath) < "" then _
fcnGetConfigLocation = myPath

End Function


HTH,
Gareth

Andibevan wrote:


Hi All,

I have a dos command that lists the location of a config file


associated

with a program.

This works fine from a dos prompt but can I use the Shell command in

such a


way that the location of the config file can be returned into VBA?

Something like Var = Shell("Getconfig") (I am aware that doing this

merely


would set Var = process thread associated with shell)

Thanks

Andi










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell command and Notepad SA3214 Excel Programming 1 May 15th 05 11:57 AM
Shell Command JOHN Excel Programming 1 November 17th 04 10:39 AM
Shell command MAx Excel Programming 2 June 4th 04 04:11 PM
xp shell command using vba Sudhendra Excel Programming 2 February 16th 04 05:56 AM
SHELL command Robin Clay[_3_] Excel Programming 3 October 17th 03 02:50 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"