ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   launch any file type from excel macro (https://www.excelbanter.com/excel-programming/304597-launch-any-file-type-excel-macro.html)

arron laing

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


Tom Ogilvy

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/




arron laing[_2_]

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


Tom Ogilvy

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/




arron laing[_3_]

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



All times are GMT +1. The time now is 02:45 PM.

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