简体   繁体   English

Excel 内置对话框

[英]Excel built-in dialogs

Does anybody know how to call the import data built-in dialog excel from a macro (vba)?有谁知道如何从宏(vba)调用import data内置对话框excel?

I've tried Application.Dialogs.Item(...).Show but I can´t find the right dialog.我试过Application.Dialogs.Item(...).Show但我找不到正确的对话框。 Please help.请帮忙。

Thanks in advance.提前致谢。

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:您可以通过以下方式获得对命令栏按钮的引用(至少对我而言在 2k3 和 2k7 中):

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

But calling the Execute method on the button fails.但是在按钮上调用Execute方法失败。 Sadly, the short answer seems to be that it's not possible.可悲的是,简短的回答似乎是不可能的。

You can add QueryTable objects by hand.您可以手动添加 QueryTable 对象。 While not an optimum path, you could design your own simple interface for selecting the source data.虽然不是最佳路径,但您可以设计自己的简单界面来选择源数据。

If you choose the Object Browser and search for say, xlDialogImportTextFile, you will get a list of possible dialogs.如果您选择对象浏览器并搜索 xlDialogImportTextFile,您将获得可能的对话框列表。

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

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.我不认为有 VBA 等价物,因为在一种情况下,您将数据返回到工作表,而在另一种情况下,数据被放入内存中的记录集中。

This kludge should pop up the dialog for you, however:这个 kludge 应该为你弹出对话框,但是:

SendKeys "%ddd"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM