Modify existing VBA to accommodate opening most recent file

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
793
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - I am looking for a way to open a file that is the most recent. I have code to open the file if it is a partial file but I have a new issue where there are two versions that were saved and just want the most recent one opened. Is someone able to assist? I would like to use the below still cause it is embedded all over my macro :)

VBA Code:
Function OpenCopyST() As Boolean
    Dim sPath       As String
    Dim sPartial    As String
    Dim sFName      As String
   
    sPath = "\\xxxxxx\xxxx$\xxxx\xxxx\xxx xxxx\"      ' <<<<< change accordingly
   
    sPartial = "vi_j_dt_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, DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1), Array(8, 2)), TrailingMinusNumbers:=True
        OpenCopyST = True
    Else
        OpenCopyST = False
    End If
End Function
 
The type mismatch error (being a run-time error) you are experiencing I cannot explain. You could have had a compile error in this line:
VBA Code:
Set OpenCopySt = Workbooks.OpenText(FullName, DataType:=xlDelimited, _

The Workbooks.Open method is actually a function because it returns a Workbook object.
The Workbooks.OpenText method on the other hand does not return a Workbook object, and the compiler starts to argue.

I have tested the code below and it does not give me any issues.

VBA Code:
Option Explicit

Public Sub Example()
    Dim MyWorkbook As Workbook
    Set MyWorkbook = OpenCopyST
    
    If Not MyWorkbook Is Nothing Then
        '
        ' do some stuff ...
        '
        ' almost finished
        '
        MyWorkbook.Close SaveChanges:=False
    End If
End Sub

Public Function OpenCopyST() As Workbook
    Dim sPath       As String
    Dim sPartial    As String
    Dim sFName      As String
   
    sPath = "\\xxxxxx\xxxx$\xxxx\xxxx\xxx xxxx\"      ' <<<<< change accordingly

    sPartial = "vi_j_dt_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)
    Dim arr() As Variant, fullname As String, i As Long
    Do While Len(sFName) > 0
        ReDim Preserve arr(i)
        arr(i) = sPath & sFName
        i = i + 1
        sFName = Dir
    Loop
    If i > 0 Then
        fullname = GetMostRecentFileFromArray(arr)

        Workbooks.OpenText fullname, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1), Array(8, 2)), TrailingMinusNumbers:=True

        Set OpenCopyST = ActiveWorkbook
    End If
End Function

Public Function GetMostRecentFileFromArray(ByRef argArr() As Variant) As String
    Dim fso As Object, i As Long, arrEntry As Long, oFile As Object, MostRecentFileDate As Double
    Set fso = VBA.CreateObject("Scripting.FileSystemObject")
    For i = LBound(argArr) To UBound(argArr)
        Set oFile = fso.GetFile(argArr(i))
        If oFile.DateLastModified > MostRecentFileDate Then
            MostRecentFileDate = oFile.DateLastModified
            arrEntry = i
        End If
    Next i
    GetMostRecentFileFromArray = argArr(arrEntry)
End Function
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
So I am getting further but now falling down other places as now it says subscript out of range on the highlighted spot. here is the whole usage of that opencopyST i was also using it to run some checks like if the file was empty, existed or not then kickout messaging.

VBA Code:
Sub RUN_Per_Dist()
    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
    Dim ErrMsg As String
    Dim ST As Workbook
    
'Set ST file to close
    Set ST = OpenCopyST

Application.ScreenUpdating = False
Application.EnableEvents = False

'find path if not found give msg (NAS Fie)
    FilePath = "\\xxxxxxxxxxxxxxxxxxxxxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml"
    
    TestStr = Dir$(FilePath)
    
    If TestStr = "" Then
        ErrMsg = "NAS File NOT FOUND"
    End If
    
'to close ST if not in use
If Not ST Is Nothing Then
    
'If found check if ST Exists
[B]    If Not OpenCopyST Then[/B]
        ErrMsg = ErrMsg & vbCrLf & "ST File NOT FOUND"
    End If

'If ST found check if ST file is NOT empty give msg end of VBA if Empty
If Range("A" & rows.count).End(xlUp).row <= 3 Then
      Call CLOSEST
      ErrMsg = ErrMsg & vbCrLf & "ST File is Empty"
   End If
   
   If ErrMsg <> "" Then
      MsgBox ErrMsg
   Else
   
'Do stuff (copy paste formulas etc)      
    
'Format ST file and copy into NAS Compare
Cells.Copy

With Workbooks("Nas Compare").Sheets("ST Per Distr")
    .Range("A1").PasteSpecial Paste:=xlPasteValues
    .Application.CutCopyMode = False
End With

'Close ST file
    ST.Close SaveChanges:=False
End If

'other stuff (copy paste formulas etc)  
    
Application.ScreenUpdating = True
Application.EnableEvents = True
    End If

Public Function OpenCopyST() As Workbook
    Dim sPath       As String
    Dim sPartial    As String
    Dim sFName      As String
   
    sPath = "\\xxxxxxxxxxx$xxxxxxxx\"      ' <<<<< change accordingly
   
    sPartial = "vi_j_dt_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)
    Dim arr() As Variant, fullname As String, i As Long
    Do While Len(sFName) > 0
        ReDim Preserve arr(i)
        arr(i) = sPath & sFName
        i = i + 1
        sFName = Dir
    Loop
    If i > 0 Then
        fullname = GetMostRecentFileFromArray(arr)

        Workbooks.OpenText fullname, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1), Array(8, 2)), TrailingMinusNumbers:=True

        Set OpenCopyST = ActiveWorkbook
    End If
End Function

Public Function GetMostRecentFileFromArray(ByRef argArr() As Variant) As String
    Dim fso As Object, i As Long, arrEntry As Long, oFile As Object, MostRecentFileDate As Double
    Set fso = VBA.CreateObject("Scripting.FileSystemObject")
    For i = LBound(argArr) To UBound(argArr)
        Set oFile = fso.GetFile(argArr(i))
        If oFile.DateLastModified > MostRecentFileDate Then
            MostRecentFileDate = oFile.DateLastModified
            arrEntry = i
        End If
    Next i
    GetMostRecentFileFromArray = argArr(arrEntry)
End Function

Sub CLOSEST()
    Dim sPath       As String
    Dim sPartial    As String
    Dim sFName      As String
   
    sPath = "\xxxxxxxxxxxx\"      ' <<<<< change accordingly
   
    sPartial = "vi_j_dt_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(sFName).Close SaveChanges:=False
    Else
    End If
End Sub
 
Upvote 0
I've restructured the logic of your macro that's using the custom function and added some clarifying comments. I'm not able to test this macro.

Note that the OpenCopyST function only needs to be invoked once.
If the workbook in question exists, it is also opened, after which the function returns a valid reference that should be stored by the calling code.
If the workbook does not exist or it fails to open, then no reference ("Nothing") is returned and the calling code may act accordingly.
Also note that your CLOSEST macro isn't needed anymore, after all, we've got a reference which can be used to close that workbook when we're done.
Hope this helps.

VBA Code:
Sub RUN_Per_Dist()
    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
    Dim ErrMsg As String
    Dim ST As Workbook

    Application.ScreenUpdating = False
    Application.EnableEvents = False

    'find path if not found give msg (NAS Fie)
    FilePath = "\\xxxxxxxxxxxxxxxxxxxxxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml"
    
    TestStr = Dir$(FilePath)
    
    If TestStr = "" Then
        ErrMsg = "NAS File NOT FOUND"
 
    Else
    
        ' the OpenCopyST function does TWO things:
        ' 1. it tries to open a certain workbook of which there could be multiple versions;
        '    get by use of a wildcard the most recent version;
        ' 2. - if the function succeeds a valid reference is returned;
        '    - if the function does NOT succeed the reference would be "Nothing"
     
        Set ST = OpenCopyST
        
        ' check whether the OpenCopyST function succeeded
        If Not ST Is Nothing Then
        
            ' opening of workbook succeeded
            'If ST found check if ST file is NOT empty give msg end of VBA if Empty
            If Range("A" & Rows.Count).End(xlUp).Row <= 3 Then
                ErrMsg = ErrMsg & vbCrLf & "ST File is Empty"
            
            Else
                'Do stuff (copy paste formulas etc)
        
                'Format ST file and copy into NAS Compare
                Cells.Copy
                
                With Workbooks("Nas Compare").Sheets("ST Per Distr")
                    .Range("A1").PasteSpecial Paste:=xlPasteValues
                    .Application.CutCopyMode = False
                End With
    
                'other stuff (copy paste formulas etc)
            End If

            'Close ST file
            ST.Close SaveChanges:=False

        
        Else
            ' opening of workbook did not succeed
            ErrMsg = ErrMsg & vbCrLf & "ST File NOT FOUND"
        End If
    End If
    
    If ErrMsg <> "" Then
        MsgBox ErrMsg
    End If

    Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub


Public Function OpenCopyST() As Workbook
    Dim sPath       As String
    Dim sPartial    As String
    Dim sFName      As String
   
    sPath = "\\xxxxxxxxxxx$xxxxxxxx\"      ' <<<<< change accordingly
   
    sPartial = "vi_j_dt_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)
    Dim arr() As Variant, FullName As String, i As Long
    Do While Len(sFName) > 0
        ReDim Preserve arr(i)
        arr(i) = sPath & sFName
        i = i + 1
        sFName = Dir
    Loop
    If i > 0 Then
        FullName = GetMostRecentFileFromArray(arr)

        Dim ErrNum As Long
        On Error Resume Next
        Workbooks.OpenText FullName, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True, Space:=False, _
                           Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 2)), _
                           TrailingMinusNumbers:=True
        ErrNum = VBA.Err.Number
        On Error GoTo 0
        If ErrNum = 0 Then
            Set OpenCopyST = ActiveWorkbook
        End If
    End If
End Function

Public Function GetMostRecentFileFromArray(ByRef argArr() As Variant) As String
    Dim fso As Object, i As Long, arrEntry As Long, oFile As Object, MostRecentFileDate As Double
    Set fso = VBA.CreateObject("Scripting.FileSystemObject")
    For i = LBound(argArr) To UBound(argArr)
        Set oFile = fso.GetFile(argArr(i))
        If oFile.DateLastModified > MostRecentFileDate Then
            MostRecentFileDate = oFile.DateLastModified
            arrEntry = i
        End If
    Next i
    GetMostRecentFileFromArray = argArr(arrEntry)
End Function
 
Upvote 0
Solution
So I am still going through some test cases. My VBA is unresponsive with the new code but that is a me issue as i found out where it is failing resolving that now to proceed.

One item so far and minor one if the file ST is empty could that stop the VBA first? Right now it is looking for the NAS file saying not found.

Process is - if ST file is not empty then the team saves the NAS file then proceeds to run the macro. So if they try to save the nas file (when they really shouldn't) it should alert them first when running the macro "hey ST file is empty what are you trying to do" (laymans terms).
 
Upvote 0
Ok i think i was able to solution. Would you mind just doing a gloss over and see if there is anything you could see as faulty or inefficient?

VBA Code:
Sub RUN_Per
    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
    Dim ErrMsg As String
    Dim ST As Workbook
    Dim wbNCOMP As Workbook
    Dim wsComp As Worksheet, wsComp1 As Worksheet, wsDIST As Worksheet, wsDIST1 As Worksheet, wsDIV As Worksheet, wsDST As Worksheet

Application.ScreenUpdating = False
Application.EnableEvents = False

'set shortcut for with sheets
With ThisWorkbook
  Set wsComp = .Sheets("Compare")
  Set wsDIST = .Sheets("ST Per")
  Set wsDIV = .Sheets("DIV")
  Set wsDST = .Sheets("DST")
End With
   
'set shortcut for sheet w/o WITH & ThisWorkbook
Set wsComp1 = Sheets("Per Compare")
Set wsDIST1 = Sheets("ST Per")

'Use either workbook extension to avoid file extension option issue
On Error Resume Next
Set wbNCOMP = Workbooks("NAS COMPARE")
Set wbNCOMP = Workbooks("NAS COMPARE.xlsm")
On Error GoTo 0

'find path if not found give msg (NAS Fie)
    FilePath = "\\xxxxxxxxxxxxxxxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml"
    
    TestStr = Dir$(FilePath)
    
    If TestStr = "" Then
        ErrMsg = "NAS DIV File NOT FOUND"
End If

        ' the OpenCopyST function does TWO things:
        ' 1. it tries to open a certain workbook of which there could be multiple versions;
        '    get by use of a wildcard the most recent version;
        ' 2. - if the function succeeds a valid reference is returned;
        '    - if the function does NOT succeed the reference would be "Nothing"
    
Set ST = OpenCopyST
    
        ' check whether the OpenCopyST function succeeded
        If ST Is Nothing Then
        ErrMsg = ErrMsg & vbCrLf & "ST File NOT FOUND"
    End If
    
        ' opening of workbook succeeded
        'If ST found check if ST file is NOT empty give msg end of VBA if Empty
        If Range("A" & rows.count).End(xlUp).row <= 3 Then
                ST.Close SaveChanges:=False
                ErrMsg = ErrMsg & vbCrLf & "ST File is Empty"
              
    End If
    
    If ErrMsg <> "" Then
        MsgBox ErrMsg
Else

'OTHER STUFF
    
'Format file and copy into Compare
Cells.Copy

With wsDIST
    .Range("A1").PasteSpecial Paste:=xlPasteValues
    .Application.CutCopyMode = False
End With

'Close ST file
    ST.Close SaveChanges:=False

'OTHER STUFF

'copy and paste file into DIV sheet
Workbooks.Open ("\\xxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml")
Cells.Copy

With wsDIV
    .Range("A1").PasteSpecial Paste:=xlPasteValues
    .Range("5:5").AutoFilter
    .Protect AllowFormattingColumns:=True, DrawingObjects:=True, Contents:=True, AllowFiltering:=True
End With

'Close File
Workbooks.Open("\\xxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml").Close SaveChanges:=False

'OTHER STUFF

'save and close
wbNCOMP.Close SaveChanges:=True

    End If
    
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
 
Upvote 0
Since I don't know exactly what the code should do and in what order, I can only make a few comments.
I haven't changed anything in your code, I just added those comments.

VBA Code:
Sub RUN_Per()
    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
    Dim ErrMsg As String
    Dim ST As Workbook
    Dim wbNCOMP As Workbook
    Dim wsComp As Worksheet, wsComp1 As Worksheet, wsDIST As Worksheet, wsDIST1 As Worksheet, wsDIV As Worksheet, wsDST As Worksheet

    Application.ScreenUpdating = False
    Application.EnableEvents = False

    'set shortcut for with sheets
    With ThisWorkbook
        Set wsComp = .Sheets("Compare")
        Set wsDIST = .Sheets("ST Per")
        Set wsDIV = .Sheets("DIV")
        Set wsDST = .Sheets("DST")
    End With
   
    'set shortcut for sheet w/o WITH & ThisWorkbook
    Set wsComp1 = Sheets("Per Compare")
    Set wsDIST1 = Sheets("ST Per")

    'Use either workbook extension to avoid file extension option issue
    On Error Resume Next
    Set wbNCOMP = Workbooks("NAS COMPARE")
    Set wbNCOMP = Workbooks("NAS COMPARE.xlsm")
    On Error GoTo 0

    'find path if not found give msg (NAS Fie)
    FilePath = "\\xxxxxxxxxxxxxxxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml"
    
    TestStr = Dir$(FilePath)
    
    If TestStr = "" Then
        ErrMsg = "NAS DIV File NOT FOUND"
    End If

    ' the OpenCopyST function does TWO things:
    ' 1. it tries to open a certain workbook of which there could be multiple versions;
    '    get by use of a wildcard the most recent version;
    ' 2. - if the function succeeds a valid reference is returned;
    '    - if the function does NOT succeed the reference would be "Nothing"
    
    Set ST = OpenCopyST
    
    ' check whether the OpenCopyST function succeeded
    If ST Is Nothing Then
        ErrMsg = ErrMsg & vbCrLf & "ST File NOT FOUND"
    
    
    End If    ' <<<< this END IF should most likely be an ELSE, because of .....

' ============================================================================================
' The code below is always executed regardless of whether the attempt to open the ST workbook was successful or not.
' That way an attempt to close that workbook in cases a prior opening attempt has failed,
' the line: [ST.Close SaveChanches:=False] will error out at run-time!
' ============================================================================================


        ' opening of workbook succeeded
        'If ST found check if ST file is NOT empty give msg end of VBA if Empty
        If Range("A" & Rows.Count).End(xlUp).Row <= 3 Then
            ST.Close SaveChanges:=False
            ErrMsg = ErrMsg & vbCrLf & "ST File is Empty"
                  
        End If
    
'   End If    ' <<<< to be added if   ELSE  is implemented like suggested
    
    
    If ErrMsg <> "" Then
        MsgBox ErrMsg
    Else


' === AGAIN: =================================================================================
' The code below is always executed regardless of whether the attempt to open the ST workbook was successful or not.
' That way an attempt to close that workbook in cases a prior opening attempt has failed,
' the line: [ST.Close SaveChanches:=False] will error out at run-time!
' ============================================================================================

        'OTHER STUFF
    
        'Format file and copy into Compare
        Cells.Copy

        With wsDIST
            .Range("A1").PasteSpecial Paste:=xlPasteValues
            .Application.CutCopyMode = False
        End With


        'Close ST file
        ST.Close SaveChanges:=False         ' <<<<<<<<<<<<< could error at run-time!!

        
        'OTHER STUFF

        'copy and paste file into DIV sheet
        Workbooks.Open ("\\xxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml")
        Cells.Copy

        With wsDIV
            .Range("A1").PasteSpecial Paste:=xlPasteValues
            .Range("5:5").AutoFilter
            .Protect AllowFormattingColumns:=True, DrawingObjects:=True, Contents:=True, AllowFiltering:=True
        End With

' ============================================
' Attempt to open an already open workbook(??)
' ============================================
        'Close File
        Workbooks.Open("\\xxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml").Close SaveChanges:=False
'                 /\/\


        'OTHER STUFF

        'save and close
        wbNCOMP.Close SaveChanges:=True

    End If
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub
 
Upvote 0
Hello will take this at parts cause you bring up some good valid points for starters:

i tried to solution this:
' ============================================ ' Attempt to open an already open workbook(??) ' ============================================ 'Close File Workbooks.Open("\\xxxxxxxxx\" & Format(Now(), "MM-DD-YY") & " " & "Div" & ".xml").Close SaveChanges:=False ' /\/\

with this

VBA Code:
Workbooks.Open (FilePath) ' to open 
Workbooks(FilePath).Close SaveChanges:=False ' to close

but now get a subscript out of range. i didnt know how to call back that workbook to close it so i realized filepath already sets the workbook can i just leverage that? but i have it set as string do i need to create a new one for workbook? it was able to open it without issue
 
Upvote 0
i didnt know how to call back that workbook to close it so i realized filepath already sets the workbook can i just leverage that?
If you set a reference to the just opened workbook, that reference can be used to close the workbook afterwards.
This way the filepath is just needed once: the moment the workbook needs to be opened.
The code below is just an example of how to manage.

VBA Code:
Dim wb as Excel.Workbook
Set wb = Excel.Application.Workbooks.Open(FilePath)     ' <<< opening a specific workbook and setting a reference at the same time
'
'
wb.Close SaveChanges:=False     ' <<< closing that specific workbook
 
Upvote 0
Cool ok I see what you mean. so it will set and open it at one go, then the latter will close. Tested that and works as you outlined>

Onto the other points you made so the reason I moved around the IF statements was i wanted a way that it would list the issues not run one then stop. so example:

NAS DIV FILE NOT FOUND
ST FIle EMPTY
ST FILE Doesn't exist

say if the ST is empty and NAS DIV is not found i wanted a warning to list both then stop the sub dont do anything further other than close the files it opened.

For example right now my NAS DIV file doesnt exist, and it isnt checking the ST file at all it just stops.
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top