File Open

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,057
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code as is all perfect, but the use is using the file ext some time as ".xlsm" or ".xls".
How should i modify the code so that if the file ext is .xlsm or .xls it will work.

any idea or suggestions.

VBA Code:
'
=====================================================================================
    'Check if all the Raw files are avalaible in folder
'=====================================================================================
If Sheets("Reference").Range("a2").Value = "" And Sheets("Reference").Range("a3").Value = "" And Sheets("Reference").Range("a4").Value = "" Then
MsgBox "Dear User all the 4 Raw files are not avalaible in folder" & vbNewLine & Fpath & vbNewLine & "Download raw file & Run the scrip again"
End
End If
  
'=====================================================================================
    ' 1. Check Raw data in folder sheet Abandon calls Report
'=====================================================================================
    If Sheets("Reference").Range("c2").Value <> "Abandon calls Report" Then
    MsgBox "Abandon calls Report Raw file not avaliable" & vbNewLine & "Download raw file & Run the scrip again", vbCritical, "Raw File Required"
    End
    End If
  
    If Len(Dir(Fpath & "\" & "Abandon calls Report.xlsx")) = 0 Then '' ---- ''Here it  can be .xlsx or .xls
    MsgBox "Abandon calls Report Raw file Not avaliable in the folder" & vbNewLine & Fpath & vbNewLine & "Download raw file & Run the scrip again"
    End
    End If
    
'=====================================================================================
    ' 1. ImportDaily Abandon calls Raw data
'=====================================================================================
        
    If Sheets("Reference").Range("c2").Value = "Abandon calls Report" Then
    
    Sheets("Abandon calls Raw data").Visible = True
    
    Windows("RTMC Daily ReportV3.xlsm").Activate
    ActiveWorkbook.Sheets("Abandon calls Raw data").Activate
    Cells.Select
    Selection.ClearContents
    Application.CutCopyMode = False
        
    Set wbsource = Workbooks.Open(Fpath & "\" & "Abandon calls Report.xlsx") '' ---- ''Here it  can be .xlsx or .xls
            
    Windows("Abandon calls Report.xlsx").Activate '' ---- ''Here it  can be .xlsx or .xls
        Cells.Select
        Selection.Copy
       Windows("RTMC Daily ReportV3.xlsm").Activate
        ActiveWorkbook.Sheets("Abandon calls Raw data").Activate
        ActiveSheet.Paste
        Application.CutCopyMode = False
    wbsource.Close
    End If
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,
try including a wildcard

Rich (BB code):
If Len(Dir(Fpath & "\" & "Abandon calls Report.xls*")) = 0 Then

Dave
 
Upvote 0
Hi Dave,
it is giving the error as file not found

VBA Code:
Set wbsource = Workbooks.Open(Fpath & "\" & "Abandon calls Report.xls*")
'' Here wildcard don't work
 
Upvote 0
Hi,
sorry, only looked at Dir function part of your code

Try replacing that section with following

VBA Code:
Dim fname
 fname = Dir(Fpath & "\" & "Abandon calls Report.xls*")
  If Len(fname) = 0 Then
    MsgBox "Abandon calls Report Raw file Not avaliable in the folder" & vbNewLine & _
    Fpath & vbNewLine & "Download raw file & Run the scrip again"
    Exit Sub
  End If

and update the workbooks.Open part with this

VBA Code:
Set wbsource = Workbooks.Open(Fpath & "\" & fname)

Dave
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,862
Members
449,052
Latest member
Fuddy_Duddy

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