![]() |
from VBA open text file in default text editor application
Is it possible from VBA to open a text file in the default text editor
application registered with Windows? I"ve tried variations of a Start command in a Shell statement, but can't find anything that works. The best I've been able to do is open the file directly with Notepad.Exe, again from a Shell statement. Thanks, Brian Murphy Austin, Texas |
from VBA open text file in default text editor application
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 Sub ABCD() Dim doc As String doc = "C:\Textfile.txt" ShellExecute 0&, vbNullString, doc, _ vbNullString, vbNullString, vbNormalFocus End Sub -- Regards, Tom Ogilvy wrote in message ps.com... Is it possible from VBA to open a text file in the default text editor application registered with Windows? I"ve tried variations of a Start command in a Shell statement, but can't find anything that works. The best I've been able to do is open the file directly with Notepad.Exe, again from a Shell statement. Thanks, Brian Murphy Austin, Texas |
from VBA open text file in default text editor application
Thanks bunches, Tom.
That does indeed do the trick. Now that I've got that working instead of having to use Notepad, I've found that I need to put a Wait call right after it to keep from executing too quickly a statement that deletes the text file that is being opened (a Kill statement). The text file being opened is a temporary file for the user to view. Two seconds seems to be enough time for the application to launch and load the file. Perhaps this is necessary because of differences between VBA's Shell command and the API's ShellExecute. Anyway, it works now. Cheers, Brian |
All times are GMT +1. The time now is 09:43 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com