vba 如何在Excel中使用vba生成范围选择对话框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7643541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:59:39  来源:igfitidea点击:

How to generate the range selection dialog box using vba in Excel?

excelvba

提问by kinkajou

I have connected excel with mssql 2008 database and now the data is filled into excel but it is not a table. I want to create a table automatically when the data load.I have used

我已将 excel 与 mssql 2008 数据库连接,现在数据已填充到 excel 中,但它不是表格。我想在数据加载时自动创建一个表。我用过

where xlWs is excel worksheet

其中 xlWs 是 Excel 工作表

Sub CreateTable(ByRef xlWs As Object)
    xlWs.ListObjects.Add(xlSrcRange, , , xlYes).Name = _
        "Table1"
        'No go in 2003
    xlWs.ListObjects("Table1").TableStyle = "TableStyleLight2"
End Subs into excel.

To make the data into table but it does not display any range dialog as it would do if I would create table using GUI. How to display such dialog?

将数据放入表格中,但不会像使用 GUI 创建表格那样显示任何范围对话框。如何显示这样的对话框?

回答by PaulStock

You cannot display the built in range dialog, but you can display a dialog box that asks for a range like this:

您无法显示内置范围对话框,但可以显示一个对话框,要求输入范围,如下所示:

Dim ThisRng As Range
Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)

回答by Patrick Honorez

I guess you could buid a form with a range control, but why not simply using ActiveCell as the destination range ?
You could eventually add a MsgBox to confirm that "Table will be created at currently active cell. Click OK to continue, or Cancel" (or something similar).

我想您可以使用范围控件来构建表单,但为什么不简单地使用 ActiveCell 作为目标范围呢?
您最终可以添加一个 MsgBox 以确认“将在当前活动单元格中创建表。单击确定继续,或单击取消”(或类似的)。