Need help converting the MS Visual Basic to something will work in EXCEL 365

SteveyDan

New Member
Joined
Oct 25, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\DefectMgmt"
.Filename = prod_rel & "_*_" & curdate & ".xls"
If .Execute = 0 Then
MsgBox "Could not find input file - ABORT"
Exit Sub
End If
End With
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Something like this might work (not tested)
VBA Code:
    Dim sPath As String, fname As String
    
    sPath = "C:\DefectMgmt\"
    fname = sPath & prod_rel & "_*_" & curdate & ".xls"
    
    With CreateObject("Scripting.FileSystemObject")
        If Not .FolderExists(sPath) Then
            MsgBox "Could not find file folder '" & sPath & "'  - ABORT", vbCritical
            Exit Sub
        End If
        
        If Not .FileExists(fname) Then
            MsgBox "Could not find input file '" & fname & "'  - ABORT", vbCritical
            Exit Sub
        End If
    End With
 
Upvote 0
VBA Code:
If Dir("C:\DefectMgmt\" & prod_rel & "_*_" & curdate & ".xls") = "" Then MsgBox "Could not find file - ABORT": Exit Sub
 
Upvote 0
Solution
Something like this might work (not tested)
VBA Code:
    Dim sPath As String, fname As String
   
    sPath = "C:\DefectMgmt\"
    fname = sPath & prod_rel & "_*_" & curdate & ".xls"
   
    With CreateObject("Scripting.FileSystemObject")
        If Not .FolderExists(sPath) Then
            MsgBox "Could not find file folder '" & sPath & "'  - ABORT", vbCritical
            Exit Sub
        End If
       
        If Not .FileExists(fname) Then
            MsgBox "Could not find input file '" & fname & "'  - ABORT", vbCritical
            Exit Sub
        End If
    End With
Thanks, I tested this out and the file existed but was not being read in to the sheet. I appreciate the effort.
 
Upvote 0
Thank you, very much this code worked.
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,224,621
Messages
6,179,937
Members
452,949
Latest member
beartooth91

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