VBA Excel - 粘贴到工作簿中的每个工作表

时间:2017-09-07 06:01:48

标签: excel vba excel-vba

我想从一个工作簿中复制一个标题,然后将其粘贴到同一范围内不同工作簿中的每个工作表。

'header
Dim OP_wb As Workbook: Set OP_wb = ActiveWorkbook
Dim header As Range
Set header = OP_wb.Sheets("Optic Main").Range("A1:F1")

Dim Part_WS As Worksheet


Demand_WB.Activate

For Each Part_WS In Demand_WB
    header.Copy
    Demand_WB.Activate
    ActiveSheet.Range("A2").Paste
Next Part_WS

我收到此错误:

  

对象不支持方法的这个属性

在线:

For Each Part_WS In Demand_WB

有人可以帮忙修复代码吗?

这是我的问题之前的代码:

Dim Demand_WB As Workbook

Workbooks.Add


For i = 1 To 5

    Worksheets.Add

Next i

ActiveWorkbook.SaveAs Filename:="C:\Users\rosipov\Desktop\eliran\MFG - GSS\Demand_Optics " & Format(Now(), "dd.mm.yyyy") & ".xlsx"



Worksheets("Sheet1").Name = "Illuminators"
Worksheets("Sheet2").Name = "Analyzers"
Worksheets("Sheet3").Name = "Chuck"
Worksheets("Sheet4").Name = "Compensators"
Worksheets("Sheet5").Name = "Spectrometers"
Worksheets("Sheet6").Name = "LDSR"

Set Demand_WB = Workbooks("C:\Users\rosipov\Desktop\eliran\MFG - GSS\Demand_Optics " & Format(Now(), "dd.mm.yyyy") & ".xlsx")

1 个答案:

答案 0 :(得分:1)

For Each Part_WS In Demand_WB.Sheets
   header.Copy
   Part_WS.Range("A2").PasteSpecial xlPasteAll 
Next Part_WS