jimbooo
03-13-2003, 10:34 AM
Hi, I'm a complete newbie, I'm trying to write a vb script to import text files into excel, selected by the user using GETOPENFILENAME. The individual macros work but i can't get the import script to accept the filename as a string.
If i get this working i'd like to get it to import multiple files at once using multiselect, positioning the data on a worksheet by using the numbers at the end of each filename:
ie. data1.prn
data2.prn
.....
data10.prn
data11.prn (note no leading zero! Nothing i can do about this)
how exactly would i use multiselect to do this? I think i can work out the loop to work out the position from the file number.
Here's the code:
Sub OpenDialog()
Dim strFileName As String
Dim strMessage As String
strFileName = Application.GetOpenFilename("Data Files (*.prn), *.prn)")
strMessage = "You selected the '" & strFileName & "' file."
MsgBox strMessage
' ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:=[strFileName], Destination:=Range("A1")) '----------- error here!!
' Import variants go here
End With
End Sub
Thanks!
If i get this working i'd like to get it to import multiple files at once using multiselect, positioning the data on a worksheet by using the numbers at the end of each filename:
ie. data1.prn
data2.prn
.....
data10.prn
data11.prn (note no leading zero! Nothing i can do about this)
how exactly would i use multiselect to do this? I think i can work out the loop to work out the position from the file number.
Here's the code:
Sub OpenDialog()
Dim strFileName As String
Dim strMessage As String
strFileName = Application.GetOpenFilename("Data Files (*.prn), *.prn)")
strMessage = "You selected the '" & strFileName & "' file."
MsgBox strMessage
' ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:=[strFileName], Destination:=Range("A1")) '----------- error here!!
' Import variants go here
End With
End Sub
Thanks!