Excel VBA - 从相同文件夹中的已关闭工作簿导入

时间:2017-08-03 08:57:58

标签: excel vba excel-vba import

我正在尝试将同一文件夹中已关闭工作簿中的某些数据导入到我的活动工作簿中。这就是我到目前为止所拥有的

Sub Import_Data()

Dim rng As Range
Dim WB2 As Workbook
Dim FName As String
Dim c1 As Worksheet
Set c1 = Sheets("c")

FName = Application.ActiveWorkbook.Path + "\_w" & Format((WorksheetFunction.WeekNum(Now) - 1), "00")
Set WB2 = Workbooks.Open(Filename:=FName)

ThisWorkbook.ChampSpecific1.Range("L3:O6").Value = WB2.Worksheets(2).Range("M3:P6").Value

WB2.Close

End Sub

当我运行宏时,我收到错误“找不到方法或数据成员”突出显示ThisWorkbook.C1.Range(c1部分)。它应该拉动工作表“c”不应该吗?

最好的问候

2 个答案:

答案 0 :(得分:2)

AFRAME.registerComponent('drawerwithinfusioncutlery',{ schema: { open : {default: '1.8 0 0.1'}, close : {default: '0 0 0.1'}, dur : {default: 300}, moveWithInfusion :{default: true}, }, update: function (){ var data= this.data; var el=this.el; var closed=true; var infusion=document.querySelector("#infusioninpack"); el.addEventListener("click",function(){ if(data.moveWithInfusion===true){ alert("true"); if(closed === true){ open(el, data.close, data.open, data.dur); open(infusion, '1.24 4.439 1.555', '3.04 4.439 1.555', data.dur); closed=false; }else if(closed===false){ open(el, data.open, data.close, data.dur); open(infusion, '3.04 4.439 1.555', '1.24 4.439 1.555', data.dur); closed=true; } }else if(data.moveWithInfusion===false){ alert("false"); if(closed === true){ open(el, data.close, data.open, data.dur); closed=false; }else if(closed===false){ open(el, data.open, data.close, data.dur); closed=true; } } }); infusion.addEventListener("click",function(){ el.setAttribute('drawerwithinfusioncutlery', {moveWithInfusion: 'false'}) }); } }); 移除ThisWorkbook.,它应该有效。像这样:

ThisWorkbook.ChampSpecific1.Range("L3:O6").Value

问题来了,因为您已经在ThisWorkbook.ChampSpecific1.Range("L3:O6")工作表上创建了一个集合,并且知道了他的ChampSpecific1。因此,如果您尝试引用新的Parent,它就不喜欢它了。

要让Parent在错误发生前的行上写下以下Parent

答案 1 :(得分:0)

您不需要ThisWorkbook限定符,因为它已经设置好了。试试这个(使用SourceShtTargetSht来避免混淆:

Sub Import_Data()
Dim SourceSht As Worksheet
Dim TargetSht As Worksheet
Dim FName As String

FName = Application.ActiveWorkbook.Path + "\AIMS_Report_w" & Format((WorksheetFunction.WeekNum(Now) - 1), "00")

Set SourceSht = Workbooks.Open(Filename:=FName).Worksheets(2)
Set TargetSht = Sheets("Summary-Champion Specific")

TargetSht.Range("L3:O6").Value = SourceSht.Range("M3:P6").Value

End Sub