PC Review


Reply
Thread Tools Rate Thread

Can I run a file with a known extension from Excel VBA

 
 
MikeZz
Guest
Posts: n/a
 
      8th Apr 2010
Hi,
I have a file with a ".mac" extention that's associated with an application
in windows.

Is there a way that I can have Excel run the file from within VBA?

Thanks
MikeZz
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      9th Apr 2010
Try something like this -

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

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Sub test()
Dim ret As Long
Dim sFile As String

sFile = "C:\Temp\test.txt"

ret = ShellExecute(GetDesktopWindow, vbNullString, sFile, _
vbNullString, vbNullString, vbNormalFocus)

If ret > 32 Then
' it worked
Else
' it failed, the code 1-32 will give the reason, eg
' 2 file not found
' 31 file not associated
Debug.Print ret
End If

End Sub

If it doesn't work and you are sure the extention is correctly associated
and sure the file is correct, try changing the first vbNullString to "open"
(with the quotes)

Regards,
Peter T


"MikeZz" <(E-Mail Removed)> wrote in message
news:0AF10904-23C9-4D7E-8745-(E-Mail Removed)...
> Hi,
> I have a file with a ".mac" extention that's associated with an
> application
> in windows.
>
> Is there a way that I can have Excel run the file from within VBA?
>
> Thanks
> MikeZz



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine Excel file version with no file extension. tjlumpkin Microsoft Excel Misc 2 23rd Jul 2009 06:59 AM
Retrieving Excel File extension based on XL File Format Enumeratio Sasikumar Kannappan Microsoft Excel Programming 2 24th Jun 2009 03:59 PM
Excel 2007 file format file extension not valid error =?Utf-8?B?TWF0dCBQaWVyY2U=?= Microsoft Excel Crashes 0 17th May 2007 04:41 PM
excel file extension =?Utf-8?B?TXIgTG9zdA==?= Microsoft Excel Misc 1 26th Apr 2007 09:01 AM
Excel File Extension Randy Microsoft Excel Programming 5 4th Dec 2003 01:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:01 AM.