VBA – Build a Custom Import Interface
Would you prefer to have control over users importing files, instead of having them use the Excel features to do it? Do you need more control over your imports for validation or modification on import? There are multiple ways to do this and just as many requirement variations, but here are some of the building blocks to start from.
1. Put the following code in a module then run it
Public Sub CustomImport()
Dim ImportFile As String
Dim ImportTitle As String
Dim TabName As String
Dim ControlFile As String
'Open common dialog and get filename
ImportFile = Application.GetOpenFilename( _
"Excel Files, *.xls, All Files, *.*")
ImportTitle = _
Mid(ImportFile, InStrRev(ImportFile, "\") + 1)
'Check cancel wasn't clicked
If ImportFile = "False" Then
TabName = "MyCustomImport"
ControlFile = ActiveWorkbook.Name
ActiveSheet.Name = TabName
Sidenote: This works well for *.xls, *.xlsx, *.xlsm, *.csv, and *.txt files. You can add or call code before the End Sub to modify the imported data before the user can touch it.