0

我以前在 Windows XP 上工作的打开/保存对话框不再在我的 Windows 7 64 位上工作。我听说“MSComDlg.CommonDialog”与 64 位不兼容。这是我的旧代码:

' Sub to show open/save dialog
SUB OpenSave (varOpenSaveInputBox, varOpenSaveType, varOpenSaveFilter)   
   ' Create object
   SET objComDlg32 = CreateObject("MSComDlg.CommonDialog")
   ' Set memory buffer
   objComDlg32.MaxFileSize = 260
   ' Set filter
   objComDlg32.Filter = varOpenSaveFilter
   ' Show dialog 
   IF varOpenSaveType = 0 Then
      objComDlg32.ShowOpen
   ELSE
      objComDlg32.ShowSave
   End IF    
   ' Get filename from dialog
   strOpenSave = objComDlg32.FileName
   ' Check IF dialog is cancelled
   IF strOpenSave <> vbNullString Then
      ' Set to variable
      objOpenSave.SetContent strOpenSave, TRUE
   End If
END SUB

如果您的回答更具体,而不是“使用这个!”,我将不胜感激。DLL 和 OCX 并不是我真正的强项。谢谢。

4

2 回答 2

0

这是 VBA,但它可能足以为您指明正确的方向。3 声明您希望打开的对话框类型。您可以在此处找到更多信息:http: //msdn.microsoft.com/en-us/library/office/ff865284.aspx

Sub FileSelect (Multi as Boolean)
' Set Dlg = Application.FileDialog(msoFileDialogFilePicker)
Set Dlg = Access.Application.FileDialog(3)
With Dlg
    .Title = "Select the file you want to open"
    .AllowMultiSelect = Multi
    If .Show = -1 Then
        txtFilePath = .InitialFileName
    Else
        Exit Function
    End If
End With

FileSelect = Dlg.SelectedItems(1)
End Function
于 2012-12-30T20:45:35.287 回答
0

我正在使用这段代码,我在互联网上的某个地方找到了它(甚至可能在 StackOverflow 上。我不记得了)

Function ChooseFile (ByVal initialDir, filter)

    dim shel, fso, tempdir, tempfile, powershellfile, powershellOutputFile,psScript, textFile
    Set shell = CreateObject("WScript.Shell")

    Set fso = CreateObject("Scripting.FileSystemObject")

    tempDir = shell.ExpandEnvironmentStrings("%TEMP%")

    tempFile = tempDir & "\" & fso.GetTempName

    ' temporary powershell script file to be invoked
    powershellFile = tempFile & ".ps1"

    ' temporary file to store standard output from command
    powershellOutputFile = tempFile & ".txt"

    'if the filter is empty we use all files
    if len(filter) = 0 then
    filter = "All Files (*.*)|*.*"
    end if

    'input script
    psScript = psScript & "[System.Reflection.Assembly]::LoadWithPartialName(""System.windows.forms"") | Out-Null" & vbCRLF
    psScript = psScript & "$dlg = New-Object System.Windows.Forms.OpenFileDialog" & vbCRLF
    psScript = psScript & "$dlg.initialDirectory = """ &initialDir & """" & vbCRLF
    'psScript = psScript & "$dlg.filter = ""ZIP files|*.zip|Text Documents|*.txt|Shell Scripts|*.*sh|All Files|*.*""" & vbCRLF
    psScript = psScript & "$dlg.filter = """ & filter & """" & vbCRLF
    ' filter index 4 would show all files by default
    ' filter index 1 would should zip files by default
    psScript = psScript & "$dlg.FilterIndex = 1" & vbCRLF
    psScript = psScript & "$dlg.Title = ""Select a file""" & vbCRLF
    psScript = psScript & "$dlg.ShowHelp = $True" & vbCRLF
    psScript = psScript & "$dlg.ShowDialog() | Out-Null" & vbCRLF
    psScript = psScript & "Set-Content """ &powershellOutputFile & """ $dlg.FileName" & vbCRLF
    'MsgBox psScript

    Set textFile = fso.CreateTextFile(powershellFile, True)
    textFile.WriteLine(psScript)
    textFile.Close
    Set textFile = Nothing

    ' objShell.Run (strCommand, [intWindowStyle], [bWaitOnReturn]) 
    ' 0 Hide the window and activate another window.
    ' bWaitOnReturn set to TRUE - indicating script should wait for the program 
    ' to finish executing before continuing to the next statement

    Dim appCmd
    appCmd = "powershell -ExecutionPolicy unrestricted &'" & powershellFile & "'"
    'MsgBox appCmd
    shell.Run appCmd, 0, TRUE

    ' open file for reading, do not create if missing, using system default format
    Set textFile = fso.OpenTextFile(powershellOutputFile, 1, 0, -2)
    ChooseFile = textFile.ReadLine
    textFile.Close
    Set textFile = Nothing
    fso.DeleteFile(powershellFile)
    fso.DeleteFile(powershellOutputFile)

End Function
于 2019-06-24T16:53:51.780 回答