将服务器上的excel文件导入另一个excel文件

我正在尝试编写一个macros将服务器上托pipe的Excel文件导入工作簿。 这是迄今为止的代码。

Sub ranker() ' ' ranker macro ' ' Range("Ranker!A10:Ranker!Z100").ClearContents URL = Range("url!F2" & i).Text With ActiveSheet.QueryTables.Add(Connection:= _ "FINDER;" & URL _ , Destination:=Range("Ranker!$A$1:$Z$100")) .Name = "ranker" .CommandType = xlCmdTable .CommandText = Array("'MTD SAR$'") .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .PreserveColumnInfo = True .Refresh BackgroundQuery:=False End With End Sub 

我唯一的问题是,它popup下面的对话框。

对话框

我需要每次select“MTD SAR $”选项。 我可以在vba代码中select这个选项来避免对话框吗? 任何帮助将不胜感激。

我不记得有能力指定你想要的工作表的查询表方法。 我已经绕过这个使用OLEDB。 这是一个例子:

 Sub Excel_QueryTable() Dim oCn As ADODB.Connection Dim oRS As ADODB.Recordset Dim ConnString As String Dim SQL As String Dim qt As QueryTable ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\SubFile.xls;Extended Properties=Excel 8.0;Persist Security Info=False" Set oCn = New ADODB.Connection oCn.ConnectionString = ConnString oCn.Open SQL = "Select * from ['MTD SAR$']" Set oRS = New ADODB.Recordset oRS.Source = SQL oRS.ActiveConnection = oCn oRS.Open Set qt = Worksheets(1).QueryTables.Add(Connection:=oRS, _ Destination:=Range("Ranker!$A$1")) qt.Refresh If oRS.State <> adStateClosed Then oRS.Close End If If Not oRS Is Nothing Then Set oRS = Nothing If Not oCn Is Nothing Then Set oCn = Nothing End Sub 

这是我使用,当然调整: 查询表与Excel作为数据源