在 VBA (msaccess) 中,当我有 unicode folder/file 名称时如何使用默认程序打开文件

in VBA (msaccess) , how to open a file with default program when I have unicode folder/file names

在 MSAccess vba 中,我想执行类似 import ShellExecute 的操作以使用其默认程序打开文件。
但我必须在文件夹或文件名中允许使用 unicode 字符(例如中文、韩文、俄文、阿拉伯文)。

有很好的ShellExecute例子
例如这里:
或此处:

很高兴知道忽略“??????”在 Access VBA 中的 UI 中的字符串中。它看起来像是变量丢失了 Unicode 值,但实际上 UI 无法显示 Unicode。如果这些值直接来自数据库,它们应该没问题。 ()。

但是中文或者韩文的路径还是打不开,全ansi的路径可以。

我正在尝试使用与上面第一个示例中相同的 declare ShellExecute,从我当前的 Access 应用程序中的链接 table 获取路径:

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 lpnShowCmd As Long) As Long



Private Sub btnLaunchFunVid1_Click()

    Dim strFileFolder As String
    Dim strFilename As String
    Dim strFullFilepath As String

    Dim rst As Recordset
    Dim qt As String
    qt = "select folderPath, filename from ClassAdmin_Videos where rowid = " & CStr(Me.cmbFunVideo1.Value)
    Set rst = CurrentDb.OpenRecordset(qt)

    strFileFolder = rst.Fields("folderPath")
    strFilename = rst.Fields("filename")

    strFullFilepath = strFileFolder & strFilename

    OpenFunVideoFileWithImportedShellExecute strFullFilepath


End Sub


Public Sub OpenFunVideoFileWithImportedShellExecute(ByVal Path As String)

    If Dir(Path) > "" Then
        ShellExecute 0, "open", Path, "", "", 0
    End If

End Sub

我可以设置允许 Unicode 的选项吗?
或者有更好的功能吗?

是的,还有更好的功能

记下您实际导入的函数:"ShellExecuteA"。

猜猜 "A" 代表什么...这是该函数的 ansi 版本。
有一个 "W" == wide == unicode 版本。

可以在此处找到一个很好的基本示例:
http://www.vbforums.com/showthread.php?511136-how-to-use-shellexecute&p=4877907&viewfull=1#post4877907

在您的代码中使用相同的代码会得到:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteW" (ByVal hwnd As Long, ByVal lpOperation As Long, ByVal lpFile As Long, ByVal lpParameters As Long, ByVal lpDirectory As Long, ByVal nShowCmd As Long) As Long  

'... 
'    [no need to change the function getting the path] 
'...

Public Sub OpenFunVideoFileWithImportedShellExecute(ByVal Path As String)

    If Dir(Path) > "" Then
        ShellExecute 0, StrPtr("Open"), StrPtr(Path), 0, 0, 1
    End If

End Sub