ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 781
- Office Version
- 365
- 2019
- Platform
- Windows
Hello - I have existing VBA that am looking to enhance currently I have 3 criteria, currently working for 1 & 3 looking to add #2:
I have #2 embedded into the VBA with another sub and currently causing issues as it doesn't stop the current VBA Test1.
I have #2 embedded into the VBA with another sub and currently causing issues as it doesn't stop the current VBA Test1.
- Stopping VBA if file 1 is missing (working)
- Stopping VBA if file 2 is missing (trying to add)
- Stopping VBA is file 2 is empty (working)
VBA Code:
Sub TEST1
Dim UsdRws As Long
Dim FilePath As String
Dim TestStr As String
Dim FoundFile As Boolean
Dim rws As Long
Dim bottomrow, lastblank As Long
Dim lr As Long
Dim vCols As Variant, vRows As Variant
Dim i As Long, k As Long
FilePath = "MY Files\" & Format(Now(), "MM-DD-YY") & " " & "TEST" & ".csv"
If FilePath <> "" Then
TestStr = Dir$(FilePath)
FoundFile = (TestStr <> "")
Else
FoundFile = False
End If
If FoundFile Then
'OTHER CODE/Processes (i.e. copying, pasting, transfering, filtering data, inputting formulas, closing files/sheets)
Call openFile2
Else
MsgBox "File is Empty"
End If
Else
MsgBox "File 1 NOT FOUND"
End If
Code:
Sub OpenFile2()
Dim sPath As String
Dim sPartial As String
Dim sFName As String
sPath = "MY FILES\" ' <<<<< change accordingly
sPartial = "dist_" & Year(Now) & IIf(Len(Month(Now)) = 1, "0" & Month(Now), Month(Now)) & IIf(Len(Day(Now)) = 1, "0" & Day(Now), Day(Now)) & "*.txt"
sFName = Dir(sPath & sPartial)
If Len(sFName) > 0 Then
Workbooks.OpenText sPath & sFName
Else
MsgBox "File not found.", vbExclamation
End If
End Sub