一般情况下我们都是通过先打开工作簿,然后在激活工作表,这样方便从表格中读取数据。但有时候我们从某个文件之读很少的关键数据,打开文件的方法就比较繁琐。这里我们可以利用一个XLM宏来实现从关闭的工作簿读取数据。这是Excel 5之前的版本中使用的旧式宏。本节包含的自定义VBA函数(GerValue)可从关闭的工作簿中检索值,如下所示:
Private Function GetValue (path,file,sheet,ref)
Dim arg As String
If Right (path, 1)"\" Then path=path & "\"
If Dir (path & file) = "" Then
GetValue="File Not Found"
Exit Function
End If
Arg="'" & path 6 &" ["& file 6&"] " & sheet & "'! " &Range (ref).Range("A1").Address (, , x1R1C1)
GetValue = ExecuteExce14Macro (arg)
End Function
这样做的好处就是比如程序的关键数据的调取不想让用户在运行过程中察觉,比如密码存储等,当我们用打开工作簿的方式读取数据时,即使你关闭屏幕更新,但依然能看到打开的工作簿过程,只是屏幕不出现闪烁感而已。
1万+

被折叠的 条评论
为什么被折叠?



