Excel 内置对话框

发布于 2024-07-07 16:25:29 字数 149 浏览 5 评论 0原文

有谁知道如何从宏(vba)调用导入数据内置对话框excel?

我尝试过 Application.Dialogs.Item(...).Show 但找不到正确的对话框。 请帮忙。

提前致谢。

Does anybody know how to call the import data built-in dialog excel from a macro (vba)?

I've tried Application.Dialogs.Item(...).Show but I can´t find the right dialog.
Please help.

Thanks in advance.

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

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

发布评论

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

评论(3

不回头走下去 2024-07-14 16:25:29

我能找到的最接近的使用对话框系统是:

Application.Dialogs(xlDialogImportTextFile).Show

您可以通过以下方式获取对命令栏按钮的引用(至少对我来说在 2k3 和 2k7 中是这样):

Set button = Application.CommandBars.FindControl(ID:=6262)

但是在按钮上调用 Execute 方法失败。 可悲的是,简短的答案似乎是不可能的。

您可以手动添加 QueryTable 对象。 虽然这不是最佳路径,但您可以设计自己的简单界面来选择源数据。

The closest I can find using the dialog system is:

Application.Dialogs(xlDialogImportTextFile).Show

You can get a reference to the command bar button (at least for me in both 2k3 and 2k7) via:

Set button = Application.CommandBars.FindControl(ID:=6262)

But calling the Execute method on the button fails. Sadly, the short answer seems to be that it's not possible.

You can add QueryTable objects by hand. While not an optimum path, you could design your own simple interface for selecting the source data.

伪装你 2024-07-14 16:25:29

如果您选择对象浏览器并搜索 xlDialogImportTextFile,您将获得可能的对话框的列表。

编辑:
也许这些方面的内容适合:

'Allow user to select text file
sf = Application _
    .GetOpenFilename("Text Files (*.txt), *.txt")
If sf <> False Then
    'Open text file
    Workbooks.OpenText sf
End If

If you choose the Object Browser and search for say, xlDialogImportTextFile, you will get a list of possible dialogs.

EDIT:
Perhaps something on these lines would suit:

'Allow user to select text file
sf = Application _
    .GetOpenFilename("Text Files (*.txt), *.txt")
If sf <> False Then
    'Open text file
    Workbooks.OpenText sf
End If
半暖夏伤 2024-07-14 16:25:29

我认为没有等效的 VBA,因为在一种情况下,您将数据返回到工作表,而在另一种情况下,数据被放入内存中的记录集中。

然而,这个拼凑应该会为您弹出对话框:

SendKeys "%ddd"

I don't think there is a VBA equivalent, because in one case you are returning data to a worksheet, while in the other case, the data is put into a recordset in memory.

This kludge should pop up the dialog for you, however:

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