我有这段代码可以使用 Ctrl+F 命令在 Excel 工作表中查找特定值,但是当代码没有找到任何内容时,我希望它抛出一条消息。
sub test()
f=5
do until cells(f,1).value=""
On Error goto hello
Cells.Find(what:=refnumber, After:=ActiveCell, LookIn:=xlFormulas, _
lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
f=f+1
hello: Msgbox"There is an error"
loop
endsub
Run Code Online (Sandbox Code Playgroud)
问题是即使没有发现错误,消息仍然会显示。我希望仅在出现错误时才显示消息框。
我有一个文件,我需要使用VBA FTP,我已经想到它的大部分,除了我需要"在文件名中插入但不能做的最后一个.
csvPath = "C:\Users\10613527\Desktop\test\"
sWorkingDirectory = csvPath
sFileToSend = "Price_Change_10-08-15 20-35-49.csv"
iFreeFile = FreeFile
Open sWorkingDirectory & FTP_BATCH_FILE_NAME For Output As #iFreeFile
Print #iFreeFile, "open " & FTP_ADDRESS
Print #iFreeFile, FTP_USERID
Print #iFreeFile, FTP_PASSWORD
Print #iFreeFile, "ASCII"
Print #iFreeFile, "put " & sWorkingDirectory & sFileToSend
Print #iFreeFile, "dir"
Close #iFreeFile
'Shell command the FTP file to the server
Shell "ftp -i -w:20480 -s:" & sWorkingDirectory & FTP_BATCH_FILE_NAME
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我得到了找不到文件的错误.
原因是文件路径和名称不在"",例如此代码正在编写另一个脚本文件并执行该文件.
所以它需要
open ftp path
username
password …Run Code Online (Sandbox Code Playgroud)