vba +从一个wb到另一个wb的复制表

时间:2016-12-02 11:00:04

标签: vba excel-vba excel

许多论坛都涵盖了这个问题。我有代码,但它一直说错误:不匹配。我不知道为什么......

我有3个WB。我正在写的那个宏(1)。需要将一张纸复制(2),然后将1 wb复制到需要将纸张复制到(3)的位置。

我在(1)中的代码::

Dim sh As Worksheet

Application.ScreenUpdating = False
Sheets("Sheet1").Select

PathNameOrigineel = Range("C2").Value
filenameOrigineel = Range("B2").Value

PathNameNew = Range("C3").Value
FilenameNew = Range("B3").Value

Set wbori = Workbooks.Open(PathNameOrigineel & filenameOrigineel)
Set wbNew = Workbooks.Open(PathNameNew & FilenameNew)

wbori.Activate
    For Each sh In wbori.Worksheets
        If sh.Name <> "Database" And sh.Name <> "Template" And sh.Name <> "Help" And sh.Name <> "OVERVIEW" And sh.Name <> "Develop" And sh.Name <> "Schedule" And sh.Name <> "Information" And sh.Name <> "Announcements" And sh.Name <> "Summary"        Then
        Sheets(sh).Copy After:=Workbooks(FilenameNew).Sheets(Sheets.Count)
        End If
    Next

1 个答案:

答案 0 :(得分:1)

sh已定义为工作表,因此您不需要Sheets(sh).Copy,只需sh.Copy

For Each sh In wbori.Worksheets
    If sh.Name <> "Database" And sh.Name <> "Template" And sh.Name <> "Help" And sh.Name <> "OVERVIEW" And sh.Name <> "Develop" And sh.Name <> "Schedule" And sh.Name <> "Information" And sh.Name <> "Announcements" And sh.Name <> "Summary"        Then
    sh.Copy After:=Workbooks(FilenameNew).Sheets(wbNew.Sheets.Count)
    End If
Next