Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open an Excel worksheet - Tool Button Macro..

Status
Not open for further replies.

basepointdesignz

Programmer
Jul 23, 2002
566
GB
Hey,

I have another question regarding tool button macros. This time I want to load an Excel worksheet from a tool button. Last time I wanted to load a .exe and thefonzzz gave me the following example as the correct macro:

^c^c(startapp "C:/Program Files/Microsoft Office/Office/WINWORD.EXE")

I tried this same code (changing the path and filename, of course) but I couldn't get it to work - the command line came up with a 'nil' value for it, even though the file existed and was in the correct place.

Obviously the startapp part of it needs to change. I tried open, openfile, startfile but nothing worked.

Please can anyone help me again..

Thanks..

Renegade..
 
The only thing you need is extra backslashes:

(startapp "C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe")
 
I tried the code you suggested and it didn't work. I'm using 2002, if that makes a difference.

I tried all sorts of variants including:

^c^c(startapp "C:/Program Files/ToolBox2002/UFO.xls")

...but the closest I got to work was with:

^c^c(open "C:/Program Files/ToolBox2002/UFO.xls")
(notice the forward slashes, it didn't seem work with back slashes, as thefonzzz suggested in a previous thread)..

I had to include one of the open parameters (r = read, w = write, a = append) - like this:

^c^c(open "C:/Program Files/ToolBox2002/UFO.xls" "a")

But it didn't work on any of them - I kept getting a nil response, suggesting the file does not exist, but it doeas and the path is exactly correct.

What do I need to do or what is the correct code to open an Excel worksheet?

I also tried the ^c^c(open "C:/Program Files/ToolBox2002/Baseplanz.dwg" "a") to open an AutoCAD drawing but it didn't work either (nil response)..

Can anyone help,

Cheers,

Renegade..
 
I am running Acad200i, not 2002, but it should not be that critical a difference.
I actually used the following routine in Autocad and it opened the file:

(startapp "C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"
"t:knt.arg")

The only difference between yours and mine is two backslashes versus one forward slash, but in Autocad syntax is critical. The exact same command written with forward slashes will not run.

The executable and the executed need their own path.
 
These also worked in Autocad 2000i:

(startapp "C:\\Program Files\\Autodesk\\AutoCAD 2000i\\acad" open "S:\\PFN\\LINK3\\Daytona_Deland\\NG582DN560.dwg")

(startapp "C:\\Program Files\\Microsoft Office\\Office\\EXCEL.EXE")

(startapp "C:\\Program Files\\Microsoft Office\\Office\\EXCEL.EXE" "t:EU_BidForm01.XLS")

These will not work because EXCEL does not recognize spaces in the file or directory name. (This may be because it is still basically a DOS based program. It opens Excel but looks for c:\documents.xls

(startapp "C:\\Program Files\\Microsoft Office\\Office\\EXCEL.EXE" "t:GA Coversheet 07-19-01.xls")

(startapp "C:\\Program Files\\Microsoft Office\\Office\\EXCEL.EXE" "C:\\Documents and Settings\\bfranzus\\My Documents\\AAAA.XLS")

 
Here's something I used to open Excel, where the file path included a space in a folder name:

(setq quotefilename (strcat "\"" filename "\""))
(startapp (findfile "excel.exe") quotefilename)

This works if excel.exe is in AutoCAD's path so it can be found by 'findfile'. The variable filename, created using 'getfiled', includes the full path. Putting the additional quotes around the path allows the use of spaces.

HTH,
Carl
 
Thank you Carl.
The trick with the "\"" is very neat.
I forgot about putting the file that you need in the AutoCad path. That solves every problem except the space in a name which is solved with the first trick.
 
Putting "s around the file name is a limitation of the OS not AutoCAD.

It will also work with the application name so

(setq app "C:\\Program Files\\Microsoft Office\\Office\\EXCEL.EXE")
(setq quoteappname (strcat "\"" app "\""))
(setq quotefilename (strcat "\"" filename "\""))
(startapp quoteappname quotefilename)

should work

Nick
nick.hall@altasystems.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top