Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default launch any file type from excel macro

I have a macro that lists all the files relating to a project in
single worksheet. As the file list and the directory tree is ver
large, I am trying to write a macro that will launch the selected fil
from the list.

I have managed to work out how to launch .xls and .doc files
using the following code by taking 'file' from the active cell


' file is the full path

If Right(file, 3) = "xls" Then
Workbooks.Open file
End If

If Right(file, 3) = "doc" Then
Set wdapp = CreateObject("Word.Application")
With wdapp
.Documents.Open file
.Visible = True
End With
End If

but this seems a bit cumbersome as there are CAD files, MS projec
files, JPGs, Acrobat files etc.

Is there a universal command that will launch any file type or som
other clever work around.

Cheers

Arro

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default launch any file type from excel macro

Use the hyperlink worksheet function to build a hyperlink


or if you want code, just use the shell command with fully qualified file
name.

As long as the extension is mapped to an application, it should work the
same as double clicking on the file in explorer.

--
Regards,
Tom Ogilvy

"arron laing " wrote in message
...
I have a macro that lists all the files relating to a project in a
single worksheet. As the file list and the directory tree is very
large, I am trying to write a macro that will launch the selected file
from the list.

I have managed to work out how to launch .xls and .doc files
using the following code by taking 'file' from the active cell


' file is the full path

If Right(file, 3) = "xls" Then
Workbooks.Open file
End If

If Right(file, 3) = "doc" Then
Set wdapp = CreateObject("Word.Application")
With wdapp
Documents.Open file
Visible = True
End With
End If

but this seems a bit cumbersome as there are CAD files, MS project
files, JPGs, Acrobat files etc.

Is there a universal command that will launch any file type or some
other clever work around.

Cheers

Arron


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default launch any file type from excel macro

I would prefer to use the code option but I have tried the help on SHEL
and I can't seem to make it work unless the file is a .exe.

I assumed the comand would be -

SHELL(file,1)

where file is the full path and filename (ie k:\project\...\test.dwg

What am I doing wrong?

Cheers

Arro

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default launch any file type from excel macro

Add START in the command line:

Shell ("Start C:\Bridge Scorer\Manual.doc")

but John Walkenbach previously posted:

The DOS Start command does not work with all versions of Windows. Try using
the ShellExecute API function.

Put this at the top of your module:

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Then use a procedure like this:

Sub OpenWordDoc()
WordDoc = "C:\Bridge Scorer\Manual.doc"
ShellExecute 0&, vbNullString, WordDoc, vbNullString, vbNullString,
vbNormalFocus
End Sub

John Walkenbach
For Excel tips, macros, & downloads...
http://j-walk.com/ss

--
Regards,
Tom Ogilvy



"arron laing " wrote in message
...
I would prefer to use the code option but I have tried the help on SHELL
and I can't seem to make it work unless the file is a .exe.

I assumed the comand would be -

SHELL(file,1)

where file is the full path and filename (ie k:\project\...\test.dwg

What am I doing wrong?

Cheers

Arron


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default launch any file type from excel macro

Thanks Tom

I found trhat previous post late on last night and managed to get i
working.

Cheers

Arro

--
Message posted from http://www.ExcelForum.com

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
Pass parameter to launch batch file with variable from excel Frank Pozzuto New Users to Excel 0 January 15th 10 06:17 PM
2007 Excel will not launch from file Barbara Excel Discussion (Misc queries) 2 July 31st 08 06:36 PM
File won't launch eric blom Excel Discussion (Misc queries) 1 September 17th 07 10:30 PM
How do I auto launch an excel file upon log in? Starion Excel Discussion (Misc queries) 1 April 24th 06 08:02 PM
Launch Macro in Access via Macro running in Excel??? dgrant Excel Programming 1 September 24th 03 01:38 PM


All times are GMT +1. The time now is 09:00 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"