“打开”>“最近的工作簿”> 选择列表中的第一个即可完成此操作。 但这可以通过代码来完成吗?看起来很容易做到,但我在这里或网上没有找到任何线索。 注-6ren">
gpt4 book ai didi

excel - 如何查找上次打开的工作簿的名称

转载 作者:行者123 更新时间:2023-12-03 02:46:55 25 4
gpt4 key购买 nike

在 Excel 2013 中,只需转到"file">“打开”>“最近的工作簿”> 选择列表中的第一个即可完成此操作。

但这可以通过代码来完成吗?看起来很容易做到,但我在这里或网上没有找到任何线索。

注意,我想我需要文件的名称+完整路径,然后一个简单的workbooks.open Filename就可以了。

另请注意,此时没有打开任何工作簿,并且 thisworkbook.name 不符合条件(否则它将无限循环打开自己)。

我在想类似的事情

Dim a as Long
Dim i as Long
Dim Str as String
a= Application.OpenworkbooksHistory.items.count
For i=1 to a
str = Application.OpenworkbooksHistory.items (i)
if str<>thisworkbook.path & "\" & thisworkbook.name then
workbooks.open str
exit sub
end if
next i

最佳答案

您将在 Application.RecentFiles 中找到最近文件的集合

要打开最后一个,只需使用Workbooks.open Application.REcentFiles(1)

或者,如果您想要更奇特的东西,您可以循环遍历它们:

For each rfile in application.recentfiles
if instr(1, rfile.name, "poop") > 0 then
Workbooks.open rfile.name
end if
next

关于excel - 如何查找上次打开的工作簿的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26185755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com