Finding a file and displaying message

Loughsie

Board Regular
Joined
Dec 18, 2006
Messages
152
I need to edit a macro that opens a file that is as .csv

what i want is if the user incorrectly places a file in folder F:\report as .rep

then i want the user to see a message that advises them of the correct format and re run

file name is opened

start of macro is Workbooks.OpenText Filename:= _
"F:\Opened.csv",

if the user put a file name opened.rep i want them to see a message

ive been messing around with a few IF statement but can seem to get it right

anyone any ideas please
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,079
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
may seem too basic

couldn't you just put a on error resume next above the open code

or on error goto message


then have a message saying:
message:
Msgbox "Couldn't find Opend.Csv, please make sure it was correctly saved in the right format"
 

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,079
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
Code:
on error goto message
Workbooks.OpenText Filename:= _ 
"F:\Opened.csv", 


goto theend
message:
msgbox "couldnt find file etc"
theend:
end sub
 

Loughsie

Board Regular
Joined
Dec 18, 2006
Messages
152
ok yeah sort of what i was thinking of just i wasnt getting code rite ..thanks ill give it a go :)
 

Forum statistics

Threads
1,181,421
Messages
5,929,805
Members
436,696
Latest member
Mr Rice

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
Top