gpt4 book ai didi

VBA - 找不到文件时的msgbox

转载 作者:行者123 更新时间:2023-12-04 21:07:59 25 4
gpt4 key购买 nike

当找不到文件 TestData.xlsx 时,我希望 msgbox 显示“找不到文件”。谢谢

Sub check()
Dim i As Long

'~~> From Row 5 to row 10
'~~> Chnage as applicable
For i = 5 To 10
Sheets("Sheet1").Range("F" & i).Formula = _
"=VLookup((CONCATENATE(C1,"" "",C" & i & _
")),'C:\Documents[TestData.xlsx]Sheet1'!$A$2:$G$28,7, FALSE)"

Sheets("Sheet1").Range("F" & i).Value = Sheets("Sheet1").Range("F" & i).Value
Next i
End Sub

最佳答案

在 for 循环之前检查文件:

If Dir$("C:\Documents\TestData.xlsx") = "" Then
MsgBox "File not found"
Exit Sub
End If

关于VBA - 找不到文件时的msgbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12010762/

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