thunderfoot
Board Regular
- Joined
- May 28, 2004
- Messages
- 229
I want to import data from an EXCEL file(1) without opening it, into another EXCEL file(2) which will be open. I want this linked to a Macro Button in file(2). I have a macro that does the job (see below) but it is a 'recorded' macro.
Sub Macro1()
'
'
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\Documents and Settings\a.n.other\Desktop\Eastlin" _
, _
"e Log.xls;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Pat" _
, _
"h="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;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:Encr" _
, _
"ypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=Fal" _
, "se"), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("'WE 01-05-09$'")
.Name = "Eastline Log_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = _
"C:\Documents and Settings\a.n.other\Desktop\Eastline Log.xls"
.Refresh BackgroundQuery:=False
End With
End Sub
This all looks a bit messy, particularly the first bit upto .CommandType = xlCmdTable.
Is there a 'cleaner' code that will do the same job?
Sub Macro1()
'
'
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\Documents and Settings\a.n.other\Desktop\Eastlin" _
, _
"e Log.xls;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Pat" _
, _
"h="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;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:Encr" _
, _
"ypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=Fal" _
, "se"), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("'WE 01-05-09$'")
.Name = "Eastline Log_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = _
"C:\Documents and Settings\a.n.other\Desktop\Eastline Log.xls"
.Refresh BackgroundQuery:=False
End With
End Sub
This all looks a bit messy, particularly the first bit upto .CommandType = xlCmdTable.
Is there a 'cleaner' code that will do the same job?