我是一个完整的 VBA 新手,但设法拼凑了以下内容,这对于我已将代码分配给命令按钮的工作表来说很好。我的问题是我的工作表有超过 3000 行,我真的不想创建 3000 个按钮。
我目前的想法是让脚本搜索一系列单元格以查找特定条件(即 TRUE),然后将我的原始代码作为与条件匹配的每个单元格的下标运行。我尝试创建一个循环来匹配正在搜索的条件,但不知道如何将结果设置为活动单元格。
谁能给我一些关于如何实现这一目标或提出更好解决方案的指示?谢谢。
Sub Send_FWU_to_E_Drive()
Dim aTemp As String
Dim bTemp As String
Dim cTemp As String
Dim dTemp As String
Dim eTemp As String
Dim subdir As String
aTemp = "c:\test\"
bTemp = "E:\romdata\"
cTemp = ActiveCell.Offset(, -5) & ".fwu"
dTemp = ActiveWorkbook.path
eTemp = "\Firmware files"
subdir = "\Firmware Files\" & ActiveCell.Offset(, -5) & "\" & ActiveCell.Offset(, -5) & ".fwu"
MsgBox "The path of the active workbook is " & dTemp & subdir
If Dir(dTemp & subdir) = "" Then
MsgBox "Please check the file and ensure it is suitable for firmware updating with an SD card."
Exit Sub
End If
MsgBox "The file " & cTemp & " is being copied to " & bTemp
If Dir("e:\romdata", vbDirectory) = "" Then MkDir "E:\romdata"
If Dir(bTemp & "nul") = "" Then
MsgBox "The Destination Directory is missing, please ensure your SD Card is formatted, mapped as drive E and has a romdata directory."
Exit Sub
End If
FileCopy dTemp & subdir, bTemp & cTemp
End Sub