从已closures,受保护的工作簿中获取值(Excel VBA,Excel4Macro)

我想从封闭受保护的工作簿(不打开工作簿)中select任何范围内的值。

我向所有相信这是一个重复的问题的人表示歉意,但是我已经尽了我的努力去寻找其他的答案,从我所看到的,似乎没有人能够解决这个问题。

到目前为止,我没有通过使用ExecuteExcel4Macro()从closures(但不是保护)的工作簿中获取值的问题,但是,我正在查询的工作簿都受到保护(使用相同的密码)。

我可以使用Workbooks.Open("wb.xls", Password:="youllneverguessit")但这需要半秒的时间才能完成,屏幕在执行时会出现Workbooks.Open("wb.xls", Password:="youllneverguessit") 。 这当然是我可以使用的东西,但是使用ExecuteExcel4Macro是即时的

当我使用ExecuteExcel4Macro()从一个closures受保护的工作簿中获取一个值时,Excel会提示我input密码,如下所示:

在这里输入图像说明

我徒劳地search了如何取消一个封闭的工作簿,并且我使用的Excel4Macro函数DEREF()没有一个参数,我可以提供密码。

理想情况下,我想有一个只需要几个参数的函数:工作簿path,工作簿名称(如果需要),范围(可以是A1 / R1C1或命名范围)和密码validation。 老实说,参数并不重要,我只需要能够以编程方式提供密码authentication。

这是我目前的:

1)使用ExecuteExcel4Macro()获取值:

使用此function从已closures且受保护的工作簿获取值时,用户必须手动提供密码。

 Function GetValue(FileName As String, _ FilePath As String, _ shtName As String, _ Rng As String) As Variant Dim rConvert As Range Dim pSht As Worksheet ' Convert our Rng string variable to R1C1 Set pSht = Workbooks("PERSONAL.XLSB").Sheets(1) Set rConvert = pSht.Range(Rng) Rng = rConvert.Address(ReferenceStyle:=xlR1C1) ' Add a backslash to the file path if the user did not If Right(FilePath, 1) <> "\" Then FilePath = FilePath & "\" GetValue = ExecuteExcel4Macro( _ "DEREF('" & FilePath & "[" & FileName & "]" & Code & "'!" & rng & ")") End Function 

2)打开工作簿,获取信息,closures工作簿:

使用此函数从closures和保护的工作簿获取值时,用户不必手动执行任何操作,但需要一些时间才能执行。

  Function get_value(wb_path As String, _ sht as string, _ rng_name As String, _ pass As String) As Variant Application.ScreenUpdating = False Application.DisplayAlerts = False Dim Rng as Range Set Rng = Workbooks.Open(wb_path, Password:=pass).Sheets(sht).Range(rng_name) get_value = Rng.Value wb.Close False Application.ScreenUpdating = True Application.DisplayAlerts = True End Function 

先谢谢你! 我感谢任何人的帮助,即使我们最终没有find答案。