0

我的任务是将最近编写的 VBA 代码转换为 OpenOffice 版本。我试图从 OpenOffice 启动它,但它不起作用(主要是“不满意的查询......”错误。我现在卡在打开文件对话框上,我可以使用 VBA 兼容的打开文件对话框,因为我现在看起来像那样(给出错误):

FileToOpen = Application.GetOpenFilename("Please choose a file to import", "Excel Files *.dbf (*.dbf)")

我也可以使用 OpenOffice 文件对话框,但找不到任何相关信息。

提前致谢

4

1 回答 1

1

我对您的要求感到困惑,但如果您在创建文件对话框时遇到问题,这是 VBA 代码可以为您完成的。我想这就是你要问的,但我可能是错的。

    Private Sub cmdFileDialog_Click()

    ' This requires a reference to the Microsoft Office 11.0 Object Library.

    Dim fDialog As Office.FileDialog
    Dim varFile As Variant

    ' Clear the list box contents.
    Me.FileList.Value = ""

    ' Set up the File dialog box.
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
    ' Change allowmultiselect to true if you want them to be able to select multiple files
    .AllowMultiSelect = False

    ' Set the title of the dialog box.
    .Title = "Select One or More Files"

    ' Clear out the current filters, and then add your own.
    .Filters.Clear
    .Filters.Add "All Files", "*.*"

    ' Show the dialog box. If the .Show method returns True, the
    ' user picked at least one file. If the .Show method returns
    ' False, the user clicked Cancel.
    If .Show = True Then
     ' Loop through each file that is selected and then add it to the list box.
     For Each varFile In .SelectedItems
        Me.FileList.Value = varFile
     Next
    Else
     MsgBox "You clicked Cancel in the file dialog box."
    End If
    End With
    End Sub
于 2013-08-13T12:19:51.147 回答