Here is the code I got from a very helpful person on this forum. I use it to import data from access but I'm sure you can adapt it to your application. This code allows you to browse your computer or network for the file you want to import.
Sub Import_Tables()
'
' Import ALL tables from Access
' Macro recorded 24/01/2008 by Chris Mann
' Application.ScreenUpdating = False
'Browse to database using prompt
Dim strPath As String
Dim vntFile As Variant
strPath = "C:\Documents and Settings\cmann29\My Documents\2007 Test Converter Tool\"
ChDrive strPath
vntFile = Application.GetOpenFilename("Database File *.mdb,*.mdb,All Files *.*,*.*")
If vntFile = False Then Exit Sub
'Import PPG table from access
Sheets("PPG").Select
Columns("A:U").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=" & vntFile, _
";Mode=ReadWrite;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path" _
, _
"="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2" _
, _
";Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encryp" _
, _
"t Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
, ""), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("PPG")
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
Hope that helps
Bookmarks