gpt4 book ai didi

excel - 使用逻辑 AND 比较两个文件名

转载 作者:行者123 更新时间:2023-12-04 20:47:36 25 4
gpt4 key购买 nike

我有以下 VBA 代码:

mainFile = ActiveWorkbook.Name
'select all excel files in this folder
fname = Dir(FPath & "\*.xls")

'go through all excel files in this folder
Do While fname <> ""
If (fname <> mainFile & fname <> uploadFile) Then
Debug.Print (mainFile & ":" & uploadFile & ":" & fname)

出于某种原因, fname <> mainFile 并没有阻止它进入循环,我从 Debug.Print 语句中得到以下信息:
函数.xls:UPLOADME.xls:函数.xls

然后代码停止执行......没有错误......什么都没有(我在循环之后有一个 Debug.Print 与其他所有内容一起被忽略)

我没有正确比较它们吗?

最佳答案

应该是:fname <> mainFile And fname <> uploadFile
在 VBA 中,&运算符用于连接字符串,而不是执行逻辑与...“与”是我正在寻找的运算符。

关于excel - 使用逻辑 AND 比较两个文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9081720/

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