ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 793
- Office Version
- 365
- 2019
- Platform
- Windows
Hello - I have VBA code what will currently check if a file exists and if it does my code will proceed if not it will give a dialog box.
Looking to add 2 more similar checks and looking to see if possible if I already have the above, the three extra are:
1) check if file A is open (one above as well) - dialog box to warn file is open
2) check if file B is open - dialog box to warn file is open
Looking to add 2 more similar checks and looking to see if possible if I already have the above, the three extra are:
1) check if file A is open (one above as well) - dialog box to warn file is open
2) check if file B is open - dialog box to warn file is open
VBA Code:
Sub Run()
Dim sPath As String, sPartial As String, sFName As String
Dim rws As Long
Application.ScreenUpdating = False
'open file using Partial file naming
sPath = "....\" ' <<<<< change accordingly
sPartial = "_US_D_" & Year(Now) & IIf(Len(Month(Now)) = 1, "0" & Month(Now), Month(Now)) & IIf(Len(Day(Now)) = 1, "0" & Day(Now), Day(Now)) & "*.csv"
sFName = Dir(sPath & sPartial)
If Len(sFName) > 0 Then
Workbooks.OpenText sPath & sFName
MY CODE
Workbooks(sFName).Close SaveChanges:=False
Else
MsgBox "File not found.", vbExclamation
End If
End Sub