ADODB.Connection-如何在封闭的xlsm工作簿中获取命名范围的“引荐”

时间:2019-04-16 08:14:43

标签: adodb named-ranges xlsm vba7

我想阅读 closed xlsm工作簿中命名范围的 refersto 属性...

我选择使用ADODB.Connection来做到这一点...(这是一个好方法???

请注意,我不想打开文件 WhatEver。 xlsm ,其中包含一个名称(在范围管理器中),名为“ _qa_NR”范围为“工作簿”,引用值为“ =“ A; B; C”

我想提取此值“ =” A; B; C“ ”(或更好的 A; B; C !)

在此先感谢您的帮助和建议!

    Dim Cn As Object 'ADODB.Connection
    Dim Fichier As String
    Dim myNamedRange As String
    Dim p

    Fichier = "C:\Users\...\WhatEver.xlsm"
    Set Cn = CreateObject("ADODB.Connection")

    With Cn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
           & Fichier & ";Extended Properties=""Excel 12.0;HDR=YES;"""
        .CursorLocation = adUseClient
        .Open
    End With

    Set Rs = CreateObject("ADODB.Recordset")
    Rs.CursorLocation = adUseClient

    myNamedRange = "_qa_NR"

    '  SELECT * FROM "_qa_NR"
    '  ==> Error "-2147217900 (80040e14)" Syntax error

    '  SELECT * FROM _qa_NR
    '  ==> Error "-2147217865 (80040e37)" Can't find object _qa_NR

    'rqt = "SELECT * FROM " & myNamedRange

    Set Rs = Cn.Execute(rqt)   ' <== fails here :(

0 个答案:

没有答案