![]() |
Opening files from Excel
I am trying open non-excel files that are not .exe files from Excel VBA
When I use the Shell command it doesn't work, I believe that this is because Shell only opens files that are .exe. Is there a method that can open other files from Excel VBA? |
Opening files from Excel
Generally opening any file requires an executable to do it wether its a .doc,
..xls or anything else Try this myfile = Shell("NOTEPAD.EXE " & "c:\lastrow.txt", vbNormalFocus) This would open lastrow.txt from the root of C with Notepad Mike "S Taylor" wrote: I am trying open non-excel files that are not .exe files from Excel VBA When I use the Shell command it doesn't work, I believe that this is because Shell only opens files that are .exe. Is there a method that can open other files from Excel VBA? |
Opening files from Excel
Thanks Mike,
The problem is that the .exe application is already open, and if I shell the executable file will create another instance of it. However if I call the file that I am trying to open it opens it from within the existing instance of the .exe file. Thanks anyway. (Hope that makes sense!) Regards Steven "Mike H" wrote: Generally opening any file requires an executable to do it wether its a .doc, .xls or anything else Try this myfile = Shell("NOTEPAD.EXE " & "c:\lastrow.txt", vbNormalFocus) This would open lastrow.txt from the root of C with Notepad Mike "S Taylor" wrote: I am trying open non-excel files that are not .exe files from Excel VBA When I use the Shell command it doesn't work, I believe that this is because Shell only opens files that are .exe. Is there a method that can open other files from Excel VBA? |
Opening files from Excel
'Put this in a module
Option Explicit 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 Function openanyfile(FileToOpen As String) Call ShellExecute(0, "Open", FileToOpen & vbNullString, _ vbNullString, vbNullString, 1) End Function 'To open a file, in this case a pdf Sub Open_file Call openanyfile("C:\My Documents\FileToOpen.pdf") end sub "S Taylor" wrote: Thanks Mike, The problem is that the .exe application is already open, and if I shell the executable file will create another instance of it. However if I call the file that I am trying to open it opens it from within the existing instance of the .exe file. Thanks anyway. (Hope that makes sense!) Regards Steven "Mike H" wrote: Generally opening any file requires an executable to do it wether its a .doc, .xls or anything else Try this myfile = Shell("NOTEPAD.EXE " & "c:\lastrow.txt", vbNormalFocus) This would open lastrow.txt from the root of C with Notepad Mike "S Taylor" wrote: I am trying open non-excel files that are not .exe files from Excel VBA When I use the Shell command it doesn't work, I believe that this is because Shell only opens files that are .exe. Is there a method that can open other files from Excel VBA? |
Opening files from Excel
Thank you Libby. That worked and was a great help.
Regards Steven "Libby" wrote: 'Put this in a module Option Explicit 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 Function openanyfile(FileToOpen As String) Call ShellExecute(0, "Open", FileToOpen & vbNullString, _ vbNullString, vbNullString, 1) End Function 'To open a file, in this case a pdf Sub Open_file Call openanyfile("C:\My Documents\FileToOpen.pdf") end sub "S Taylor" wrote: Thanks Mike, The problem is that the .exe application is already open, and if I shell the executable file will create another instance of it. However if I call the file that I am trying to open it opens it from within the existing instance of the .exe file. Thanks anyway. (Hope that makes sense!) Regards Steven "Mike H" wrote: Generally opening any file requires an executable to do it wether its a .doc, .xls or anything else Try this myfile = Shell("NOTEPAD.EXE " & "c:\lastrow.txt", vbNormalFocus) This would open lastrow.txt from the root of C with Notepad Mike "S Taylor" wrote: I am trying open non-excel files that are not .exe files from Excel VBA When I use the Shell command it doesn't work, I believe that this is because Shell only opens files that are .exe. Is there a method that can open other files from Excel VBA? |
All times are GMT +1. The time now is 02:13 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com