软件:EXCEL
版本:2010
我想要将其他没开启的活页簿中的某一分页,复制到我现在的活页簿新增的工作表中
在网络上找到其他大神提供的方法如下,我把他改成放在D槽,
但是执行的时候如果没有开启"D:\Book2.xls"这个活页簿,都会在错误那行,
必须要活页簿开启的状态下才能成功,请问有什么方法可以不开启活页簿就直接复制过来?
谢谢
资讯如下:
把 Excel 活页簿当成来源数据库:
假设要汇入 "D:\Book2.xls" 的 "sheet3", 不需开启 "D:\Book2.xls"
:
Sub 工作表汇入()
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User
ID=Admin;Data Source=D:\Book2.xls;Mode=Share Deny Write;Extended
Properties=""H" _
, _
"DR=NO;"";Jet OLEDB:System database="""";Jet OLEDB:Registry
Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=35;Jet OLED"
_
, _
"B:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Passwo" _
, _
"rd="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt
Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet O" _
, "LEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"),
Destination _
:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("Sheet3$")
.Name = "Book2"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = "D:\Book2.xls"
.Refresh BackgroundQuery:=False '错误错误错误错误错误
End With
End Sub