单击链接从网络驱动器打开文件 - 采用 Microsoft Access 形式

发布于 2025-01-14 00:14:18 字数 309 浏览 3 评论 0原文

我有下面的代码来打开文件位置文件夹,但是我想打开文件本身而不是文件夹位置。

有人可以建议我应该在代码中更改什么吗?

Private Sub File_locationButton_Click()

    Dim filePath
    filePath = File_Location 

    Shell "C:\WINDOWS\explorer.exe """ & filePath & "", vbNormalFocus

End Sub

I have the below code to open a file location FOLDER, however I would like to open the file itself instead of folder location.

Can someone suggest what should I change in the code.

Private Sub File_locationButton_Click()

    Dim filePath
    filePath = File_Location 

    Shell "C:\WINDOWS\explorer.exe """ & filePath & "", vbNormalFocus

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高跟鞋的旋律 2025-01-21 00:14:18

您可以使用 ShellExecute,因此:

Private Sub File_locationButton_Click()

    Dim filePath
    filePath = File_Location 

    OpenDocumentFile filePath

End Sub

它调用:

Option Compare Database
Option Explicit

' API declarations for OpenDocumentFile.
' Documentation:
'   https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
'
Private Declare PtrSafe 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 Declare PtrSafe Function GetDesktopWindow Lib "USER32" () _
    As Long
    
' ShowWindow constants (selection).
' Documentation:
'   https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
'
Private Const SwShowNormal      As Long = 1
Private Const SwShowMinimized   As Long = 2
Private Const SwShowMaximized   As Long = 3

    
' Open a document file using its default viewer application.
' Optionally, the document can be opened minimised or maximised.
'
' Returns True if success, False if not.
' Will not raise an error if the path or file is not found.
'
' 2022-03-02. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function OpenDocumentFile( _
    ByVal File As String, _
    Optional ShowCommand As Long = SwShowNormal) _
    As Boolean

    Const OperationOpen     As String = "open"
    Const MinimumSuccess    As Long = 32
    ' Shall not have a value for opening a document.
    Const Parameters        As String = ""
    
    Dim Handle      As Long
    Dim Directory   As String
    Dim Instance    As Long
    Dim Success     As Boolean
    
    Handle = GetDesktopWindow
    Directory = Environ("Temp")

    Instance = ShellExecute(Handle, OperationOpen, File, Parameters, Directory, ShowCommand)
    ' If the function succeeds, it returns a value greater than MinimumSuccess.
    Success = (Instance > MinimumSuccess)
    
    OpenDocumentFile = Success

End Function

You can use ShellExecute, so:

Private Sub File_locationButton_Click()

    Dim filePath
    filePath = File_Location 

    OpenDocumentFile filePath

End Sub

which calls:

Option Compare Database
Option Explicit

' API declarations for OpenDocumentFile.
' Documentation:
'   https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
'
Private Declare PtrSafe 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 Declare PtrSafe Function GetDesktopWindow Lib "USER32" () _
    As Long
    
' ShowWindow constants (selection).
' Documentation:
'   https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
'
Private Const SwShowNormal      As Long = 1
Private Const SwShowMinimized   As Long = 2
Private Const SwShowMaximized   As Long = 3

    
' Open a document file using its default viewer application.
' Optionally, the document can be opened minimised or maximised.
'
' Returns True if success, False if not.
' Will not raise an error if the path or file is not found.
'
' 2022-03-02. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function OpenDocumentFile( _
    ByVal File As String, _
    Optional ShowCommand As Long = SwShowNormal) _
    As Boolean

    Const OperationOpen     As String = "open"
    Const MinimumSuccess    As Long = 32
    ' Shall not have a value for opening a document.
    Const Parameters        As String = ""
    
    Dim Handle      As Long
    Dim Directory   As String
    Dim Instance    As Long
    Dim Success     As Boolean
    
    Handle = GetDesktopWindow
    Directory = Environ("Temp")

    Instance = ShellExecute(Handle, OperationOpen, File, Parameters, Directory, ShowCommand)
    ' If the function succeeds, it returns a value greater than MinimumSuccess.
    Success = (Instance > MinimumSuccess)
    
    OpenDocumentFile = Success

End Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文