开发者

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

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

where xlWs is excel worksheet

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?


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)


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜