Programming Excel to open a program

D

DGreco

I have an application where I want Excel to open a file listed in a
spreadsheet. This spreadsheet contains a list of Autocad drawings. Ordinarily
I'd just use the Hyperlink function to allow the user to click on it and
AutoCad will open the file. However, we have limited netowrk licenses and
they are assigned on a first come basis. If all of the licenses are in use,
and someone tried to open a drawing with AutoCad it will fail. I'd like to
make it so that when the user clicks on the filename, an Autocad viewer will
open.

I was thinking that a command button with some embedded code would do the
trick. The code would look at the cell and get the filename (which includes
the entire path to the drawing). Then the program would open it with the
drawing viewer.

However, I'm at a loss as to HOW to do this. Any help?

DGreco
 
J

Jacob Skaria

Use SHELL. Refer below example

Shell("C:\WINDOWS\NOTEPAD.EXE " & filename, vbNormalFocus)

If this post helps click Yes
 
J

Jacob Skaria

Create a file c:\1.txt and try tbe below from Immediate window

shell "c:\windows\NOTEPAD.exe" "C:\1.txt"
 
D

DGreco

Thanks for the sample code. I understand the concept. The shell command will
open NotePad. But I believe the code in the example is not formatted
correctly to get Notepad to open up the file, "C:\1.txt". I tried it out and
it didn't work. I get this error message:

Compile Error
Syntax Error

This leads me to my next question. I would assume that if the drawing name
is in cell "B2", I can use the following code to save the contents of "B2" to
a variable name.

Set strFname = Range("c2").Value

But if I do this, I get a syntax error because the value of the cell is not
a text string. I would assume that I have to convert it to a string in order
to use in in conjunction with the SHELL command. Correct? if so, how do I
pass the contents of the cell to the shell command in a format is can use?
 
A

aamer

i want to know wether we can delete the row which has comon items(by using
any function) pls help
 
T

Tushar Mehta

To insert a double-quote use two double-quotes.

So, assuming your notepad program is in c:\windows and the file of interest
is c:\a b c.txt (I intentionally added spaces to the file name for my test),
use

Shell "c:\windows\notepad.exe ""c:\a b c.txt""", vbNormalFocus

To refer to the file in cell C2, use

Shell "c:\windows\notepad.exe """ & Range("c2").Value & """",
vbNormalFocus
--
Tushar Mehta
http://www.tushar-mehta.com
Custom business solutions leveraging a multi-disciplinary approach
In Excel 2007 double-click to format may not work; right click and select
from the menu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top