E
Emiliano
Hello,
I've a sheet with a range "DataList" linked to external data I refresh
with the following code got from the macro recording command and
sligtly modified according to my needs:
Sub RangeRefresh(Password As String, DataSource As String, destination
As String, _
ListName As String, RangeName As String, Fileodc As String)
'
' Macro1 Macro
' Macro registrata il 18/12/2008 da Emiliano Paperfetti
'
Dim appath As String
appath = ThisWorkbook.Path & "\"
'
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User
ID=Admin;Data Source=" & appath & OrigineDati & ";Mode=Share Deny
Write;Extended Propert" _
, _
"ies="""";Jet OLEDB:System database="""";Jet OLEDB:Registry
Path="""";Jet OLEDBatabase Password=" & Password & ";Jet OLEDB:Engine
Type=5;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:Encrypt
Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLE" _
, "DB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False"), Destination _
:=Range(dest))
.CommandType = xlCmdTable
.CommandText = Array(NomeElenco)
.Name = NomeRange
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceConnectionFile = appath & Fileodc
.SourceDataFile = appath & OrigineDati
.Refresh BackgroundQuery:=False
End With
End Sub
Before to modify the VBA code I refreshed "DataList" manually by the
External Data Toolbar. Since "DataList" has a more little range (named
"LittleRange") in it, this range resized its columns lenght according
to the recordcount of the "DataList" range.
This automatic resize does not happens with the VBA macro.
Someone knows why the VBA macro behavior differs from that of the
manual refreshment?
Thanks and best wishes to all.
Emiliano
I've a sheet with a range "DataList" linked to external data I refresh
with the following code got from the macro recording command and
sligtly modified according to my needs:
Sub RangeRefresh(Password As String, DataSource As String, destination
As String, _
ListName As String, RangeName As String, Fileodc As String)
'
' Macro1 Macro
' Macro registrata il 18/12/2008 da Emiliano Paperfetti
'
Dim appath As String
appath = ThisWorkbook.Path & "\"
'
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User
ID=Admin;Data Source=" & appath & OrigineDati & ";Mode=Share Deny
Write;Extended Propert" _
, _
"ies="""";Jet OLEDB:System database="""";Jet OLEDB:Registry
Path="""";Jet OLEDBatabase Password=" & Password & ";Jet OLEDB:Engine
Type=5;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:Encrypt
Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLE" _
, "DB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False"), Destination _
:=Range(dest))
.CommandType = xlCmdTable
.CommandText = Array(NomeElenco)
.Name = NomeRange
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceConnectionFile = appath & Fileodc
.SourceDataFile = appath & OrigineDati
.Refresh BackgroundQuery:=False
End With
End Sub
Before to modify the VBA code I refreshed "DataList" manually by the
External Data Toolbar. Since "DataList" has a more little range (named
"LittleRange") in it, this range resized its columns lenght according
to the recordcount of the "DataList" range.
This automatic resize does not happens with the VBA macro.
Someone knows why the VBA macro behavior differs from that of the
manual refreshment?
Thanks and best wishes to all.
Emiliano