Code to open a Wordpad file from a button?

jim84

Registered User.
Local time
Today, 04:54
Joined
Nov 4, 2002
Messages
23
Does anyone know the code for opening a specific notepad file from a button? I know there's a default button but it only opens a blank notepad page. I need to open some written instructions from a button you see.

Thanks.
 
Look at Shell and FollowHyperlink in VBA Help.
 
Thank you, got it sorted now :)
 
With Notepad, since it falls under the Windows System directory, all you have to do is:
Code:
Shell "notepad.exe " & FilePath

However, if you want to use Wordpad, which is installed under a different directory, the following will not work:
Code:
Shell "wordpad.exe " & FilePath

The following function will open wordpad with a specified file:
Code:
Public Function OpenWordpadFile( _
    ByVal PathName As String, _
    Optional WindowStyle As VBA.VbAppWinStyle = vbMinimizedFocus) As Double

Dim WshShell As Object

Set WshShell = CreateObject("WScript.Shell")

OpenWordpadFile = WshShell.Run(WshShell.RegRead( _
    "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WORDPAD.EXE\") _
    & " """ _
    & PathName _
    & """", WindowStyle, False)

Set WshShell = Nothing

End Function

Example:

OpenWordpadFile "C:\MyFolder\MyFile.txt", vbNormalFocus
 

Users who are viewing this thread

Back
Top Bottom