打开c:\a.txt怎么写代码
为何不能用shell函数。它只能打开可执行文件么,哪些属于可执行文件

解决方案 »

  1.   

    Private Sub Form_Load()
            Shell "notepad.exe " & "D:\a.txt"
    End Sub
      

  2.   

    Private Sub Command1_Click()
    Shell "notepad.exe c:\a.txt", vbNormalFocus
    End Sub
      

  3.   

    Private Sub Form_Load()
            Shell "notepad.exe " & "D:\a.txt"
    End Sub
      

  4.   

    Private Sub Command1_Click()
        Dim k As Integer
        k = Shell("notepad.exe c:\a.txt", 1)
    End Sub
    或者调用API函数: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 LongPrivate Const HWND_TOP = 0
    Private Const SW_SHOWNORMAL = 1Private Sub Command1_Click()
        dim i as interger
        i = ShellExecute(HWND_TOP, "open", "NOTEPAD.EXE", "a", "c:\", SW_SHOWNORMAL)  '打开c:\a.txt文件
    End Sub