VBA Code Error 5

Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
When running this macro to upload a file and pull in data everything works great during the debug until I F8 after the tmpVal code

Not sure exactly what the problem might be but it looks like something in the esName is causing a problem?

Currently this report is only pulling data for xlsx files but I need it to be able to pull xlsx or xls.

Code:
'esName = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx; *.xls", Title:="Please select a file")
esName = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx; *.xls), OpenFiles", Title:="Please select a file")


Code:
tmpStart = InStr(esName, ".xlsx")    tmpVal = Mid(esName, 1, tmpStart - 1)
    New_esName = tmpVal + "_data.xlsx"
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
If you pick an XLS file, InStr(esName, ".xlsx") is 0, so tmpStart - 1 is -1, and the Mid function doesn't like that.
 
Upvote 0
I changed the InStr(esName, ".xls") instead of xlsx and it appears I can now pull both types of files without any issues.
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,636
Members
452,662
Latest member
Aman1997

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