Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
'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? |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel files not opening | Excel Discussion (Misc queries) | |||
show most recent files first when opening excel files | Excel Discussion (Misc queries) | |||
Excel files not opening | Excel Discussion (Misc queries) | |||
Opening Quattro Pro for Windows files (*.WB1 Files) using Excel 20 | Excel Discussion (Misc queries) | |||
Excel and opening files | Excel Discussion (Misc queries) |