Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

To Open WordPad File from VB

Posted on 2002-06-29
3
Medium Priority
?
986 Views
Last Modified: 2012-08-13
We can open any  exicutable file from VB using Shell command ,
ie :  shell "c:\windows\write.exe"   but here I want to open a particular wordpad file from VB
   How can I give name of the file as argument .
     and note that -> if we have installed MSOFFICE in our System  , wordpad file will automatically open in MS WORD ,
       I want the file to open  in Wordpad itself

     -> in short, I want to open a particular file in Wordpad itself from VB

advanced sweet thanks for helping
0
Comment
Question by:romance
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 200 total points
ID: 7118839
Hi romance,

an easy way would be
Shell "C:\Program Files\Accessories\WORDPAD.EXE MyFilePath"

more safe way from a newsgroup post by Joe Le Vasseur

___________snip__________________________________________

Here is how I would do it. This should work even if someone has removed/uninstalled WordPad.

Option Explicit
Private Declare Function FindExecutable Lib "shell32.dll" _
   Alias "FindExecutableA" _
  (ByVal lpFile As String, _
   ByVal lpDirectory As String, _
   ByVal sResult As String) As Long

Private Sub Command1_Click()
    Dim lRet As Long
    lRet = Shell(AssociatedEXE("WRI") & " " _
        & "C:\Autoexec.bat", vbNormalFocus)
End Sub

Public Function AssociatedEXE(Ext As String) As String
   Dim iFN                          As Integer
   Dim lRet                         As Long
   Dim szResult                     As String
   Dim szTmpFile                    As String
   Const MAX_PATH                   As Long = 260
   Const FE_SUCCESS                 As Long = 32
   '-------------------------------------------------
   On Error GoTo errAssociatedEXE
   szResult = Space$(MAX_PATH)
   iFN = FreeFile
   szTmpFile = HomeDirectory() & "AE_TMP." & Ext
   If FileExists(szTmpFile) Then
      Kill (szTmpFile): DoEvents
   End If
   Open szTmpFile For Random As #iFN
   Close #iFN: DoEvents
   lRet = FindExecutable(szTmpFile, "", szResult)
   If (lRet >= FE_SUCCESS) Then
      lRet = InStr(szResult, Chr$(0))
      If (lRet > 0) Then
         szResult = Left$(szResult, lRet - 1)
      End If
   End If
   szResult = Trim$(szResult)
   If FileExists(szTmpFile) Then
      Kill (szTmpFile): DoEvents
   End If
   AssociatedEXE = szResult
Exit Function
errAssociatedEXE:
   Close #iFN
   Resume Next
End Function

Public Function HomeDirectory() As String
    HomeDirectory = App.Path & IIf(Right$(App.Path, 1) = "\", "", "\")
End Function

Public Function FileExists(ByVal szFileName As String) As Boolean
' ///////////////////////////////////////////////////
' Purpose: See function name                       '/
' Parameters: String containing file name          '/
' Return Value: True/False                         '/
'////////////////////////////////////////////////////
   Dim AttrRet         As Integer
   Dim bIsDirectory    As Boolean
   '------------------------------------------------
   On Error Resume Next
   AttrRet = GetAttr(szFileName)
   If Err.Number Then
      Err.Clear
      FileExists = False
   Else
      bIsDirectory = CBool((AttrRet And vbDirectory) = vbDirectory)
      If (bIsDirectory = False) Then
         FileExists = True
      Else
         FileExists = False
      End If
   End If
End Function
___________snip__________________________________________


HAGD:O)Bruintje
0
 

Expert Comment

by:salman_ilm
ID: 7120261
you can use SHELL command in VB
shell ("path of any program to be run")

0
 
LVL 44

Expert Comment

by:bruintje
ID: 7120374
that was the easy way already stated
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question