Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 151
Default 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
STe STe is offline
external usenet poster
 
Posts: 3
Default 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?



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
Excel files not opening Trizia Excel Discussion (Misc queries) 3 May 18th 08 11:44 AM
show most recent files first when opening excel files Anne` Excel Discussion (Misc queries) 5 January 23rd 08 01:54 AM
Excel files not opening [email protected] Excel Discussion (Misc queries) 13 November 16th 07 03:58 PM
Opening Quattro Pro for Windows files (*.WB1 Files) using Excel 20 PoundMutt Excel Discussion (Misc queries) 1 June 20th 07 03:50 AM
Excel and opening files Jon Scales Excel Discussion (Misc queries) 2 September 12th 05 01:49 PM


All times are GMT +1. The time now is 09:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"