I wish to run a Macro that will open all files I place in a folder automatically (once macro run), then search in each of those files for a variable value (which is different each time as it is a temperature, so can be 8.1, 9.3 etc.) and then if that value is found to call another macro, if the value isn't found to close that workbook so only work books that have found the value will be left open.
So I have tried this numerous ways and got to the below but its not working for me. any help/advise would be appreciated. To adjust the variable figure I would open the macro in VBA and change the value each time before running it.
' Auto_Find_Value Macro
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Application.ScreenUpdating = False
Sub OpenFiles()
Dim MyFolder As String
Dim MyFile As String
MyFolder = "\\labsrv-control\UserMyDocs\jb1\Documents\CSV Files to auto open"
MyFile = Dir(MyFolder & "\*.csv")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
MyFile = Dir
If Cells.Find(What:="9.1", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate Then
Call All
ElseIf ??? not sure on this part??? = value not found Then
ActiveWorkbook.Close False
Application.ScreenUpdating = True
End If
Loop
End Sub
Aucun commentaire:
Enregistrer un commentaire