gpt4 book ai didi

excel - 在当前目录中打开工作簿

转载 作者:行者123 更新时间:2023-12-04 21:50:39 24 4
gpt4 key购买 nike

我有一个包含文件列表的主工作簿 (E14:E26) ,其中一些是空白(空)单元格。我需要代码来遍历列表并打开列出的工作簿(所有这些都在当前目录中)。我试过这段代码,但收到错误消息:

Sub SkipBlankCells()
Dim cell As Range, rng As Range, FName As String

Set rng = Range("E14:E26")

For Each cell In rng
If Not IsEmpty(cell) Then
FName = cell.Value
Workbooks.Open Filename:=FName
End If
Next cell
End Sub

最佳答案

我想单元格不包含工作簿的整个路径,只是文件名,所以这应该可以工作:

    Sub SkipBlankCells()
Dim cell As Range, rng As Range, FName As String

Set rng = Range("E14:E26")

For Each cell In rng
If Not IsEmpty(cell) Then
FName = vbNullString
FName = Dir(thisworkbook.Path & "\" & cell.Value) 'use dir to get the filename. If it doesn't exists, it will return blank
If Not FName = vbNullString then Workbooks.Open _
Filename:=Thisworkbook.Path & "\" & FName 'to open a workbook you need the whole path to it, not only the file name.
End If
Next cell
End Sub

关于excel - 在当前目录中打开工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54920576/

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