Shell "rundll32.exe shell32.dll,OpenAs_RunDLL " & FileName 'FileName是打开的文件。

解决方案 »

  1.   

    '新建一个工程,在form1中添加两个textbox和一个command button
    'text1用来输入文件名
    'text2用来输入路径名
    '如果text1中包含了完全路径,则text2被忽略
    '把一下代码添加到form1中,按F5运行…………Option Explicit
    Const SW_SHOWNORMAL = 1
    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
    Private Sub Command1_Click()
        
        ShellExecute Me.hwnd, "open", Text1.Text, vbNullString, Text2.Text, SW_SHOWNORMALEnd Sub这是第二个例子Const SEE_MASK_INVOKEIDLIST = &HC
    Const SEE_MASK_NOCLOSEPROCESS = &H40
    Const SEE_MASK_FLAG_NO_UI = &H400
    Private Type SHELLEXECUTEINFO
        cbSize As Long
        fMask As Long
        hwnd As Long
        lpVerb As String
        lpFile As String
        lpParameters As String
        lpDirectory As String
        nShow As Long
        hInstApp As Long
        lpIDList As Long
        lpClass As String
        hkeyClass As Long
        dwHotKey As Long
        hIcon As Long
        hProcess As Long
    End Type
    Private Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As Long
    Sub ShowProps(FileName As String, OwnerhWnd As Long)
        Dim SEI As SHELLEXECUTEINFO
        Dim r As Long
        With SEI
            'Set the structure's size
            .cbSize = Len(SEI)
            'Seet the mask
            '.fMask = SEE_MASK_INVOKEIDLIST
            .fMask = 0
            'Set the owner window
            .hwnd = OwnerhWnd
            'Show the properties
            .lpVerb = "OpenAs"
            'Set the filename
            .lpFile = FileName
            .lpParameters = vbNullChar
            .lpDirectory = vbNullChar
            .nShow = 0
            .hInstApp = 0
            .lpIDList = 0
        End With
        r = ShellExecuteEx(SEI)
    End Sub
    Private Sub Form_Load()
        ShowProps "c:\05150642.LOG", Me.hwnd
    End Sub