Unable to query named range on sheet with spaces in name in Excel

前端 未结 5 1483
我寻月下人不归
我寻月下人不归 2021-01-18 14:21

I have a workbook with multiple sheets, and each sheet has the same set of named ranges (IE they are scoped to the sheet, not workbook).

I want to query based on a n

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 14:50

    Another late entrance to the party...

    I couldn't get any of the responses here to work for the entire sheet, so I made a named range for the whole sheet (select all cells and give them a name - I called them POList) and referred to that thus:

    UPDATE [POList] SET..... etc
    

    So no single quotes, no backticks, no $ sign, not even the sheet name.

    Having said that, the workbook in question only has the one sheet (which DOES have spaces in the name).

    This works using Excel 2002 (!) and the following connection code

    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    With cn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .ConnectionString = "Data Source=C:\Purchase Req No. List.xls; Extended Properties=Excel 8.0;"
        .Open
    End With
    

    Obviously this won't work for everyone's situation and is a bit of a kludgey workaround, but maybe someone will find it useful...

提交回复
热议问题