0

以前はWindowsXPで機能していた[開く/保存]ダイアログボックスが、Windows764ビットでは機能しなくなりました。'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 に答える