PDA

View Full Version : Import data file



ermis1975
08-05-2008, 01:57 AM
I want to be prompt to import a csv file. Different name every time.
Numbers as numbers and text as text.

Bob Phillips
08-05-2008, 02:33 AM
Look at FileDialog in VBA Help.

ermis1975
08-06-2008, 05:20 AM
Any code?

Kenneth Hobs
08-06-2008, 10:42 AM
Do you not know how to use the help? Just press F1 with the cursor in a word in the Visual Basic Editor or search for it in the F2 dialogs.

Here is a function for you and an example on how to use it.

Sub TestCSVOpen()
Dim f As String
f = CSVFile("c:\myfiles\excel\test.csv", "Select CSV File")
MsgBox f
End Sub

Function CSVFile(sPath As String, sTitle As String) As String
' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
.initialFilename = sPath
.Title = sTitle
.Filters.Add "CSV Files", "*.csv", 1
.AllowMultiSelect = False

If .Show = -1 Then
MsgBox "here"
CSVFile = .SelectedItems(1)
Else: CSVFile = ""
End If
End With
End Function