VBA coding to click OKAY past CSV SYLK error

hwkeyser

Board Regular
Joined
Jun 7, 2011
Messages
116
Hey all,

I have a VBA code to open a CSV file:

Code:
FileToOpen = Application.GetOpenFilename _(Title:="Please choose the Permit List to import", _
FileFilter:="CSV files only (*.csv),")


If FileToOpen = False Then
MsgBox "No file specified."
Exit Sub
Else
Workbooks.Open Filename:=FileToOpen

The CSV which the workbook is designed to open is being downloaded from a gov't website and because the first column is "ID" it arrives an error msgbox:

Code:
vba file is a SYLK file, but cannot load it. Either the file has errors or it is not a SYLK file format. Click OK to try to open the file in a different format.

Is there a variable or a code I can add into my workbooks.open to just click OKAY when the above msgbox opens and my coworkers (who i'm making this for) can maintain their sense of calm?

Thanks,

HK
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello, I know this is a really old post, but if anyone runs across it, here is the VBA solution:

I was using a macro to convert text files to XLSX and one of the text files had "ID" in the first two characters. EXCEL automatically labels files like this as SYLK files and throws popups asking what you want to do about it (I know, it is ridiculous, but true). I tried a suggestion to convert the file to UTF-8, but then my pipe delimiter was not recognized. After trying may different things, I finally found a very simple solution.

I hope this helps those of you who have been pulling your hair out over this!

Application.DisplayAlerts = False
Workbooks.Open Filename:=folderName & "\" & myfile, Format:=6, Delimiter:="|"
Application.DisplayAlerts = True

Be simply adding the DisplayAlerts statements, it powered right through the popups and handled my file correctly.

Annette
 
Upvote 0

Forum statistics

Threads
1,215,357
Messages
6,124,482
Members
449,165
Latest member
ChipDude83

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