将工作表复制到另一个工作簿 - 路径错误

时间:2017-07-27 13:36:42

标签: excel vba excel-vba path

我正在尝试编写代码来将工作表复制到打开的工作簿。但是我最后得到了一个路径错误。

代码现在看起来像这样;

Sub Storyboard_Ekle()
    Dim DosyaSec As Office.FileDialog

    Set DosyaSec = Application.FileDialog(msoFileDialogFilePicker)

   With DosyaSec

      .AllowMultiSelect = False
      .Title = "Lütfen yeni eklenecek Storyboard dosyasini seçiniz."
      .Filters.Clear
      .Filters.Add "Excel Macro-Enabled Workbook", "*.xlsm"
      .Filters.Add "Excel Workbook", "*.xlsx"
      .Filters.Add "All Files", "*.*"

      If .Show = True Then
        YeniSB = .SelectedItems(1)
      End If

Dim YeniStoryBoard As Workbook
Dim AnaDosya As Workbook
Dim YeniStoryBoard_Sheet As Worksheet
Dim AnaDosya_Sheet As Worksheet

Application.ScreenUpdating = False

Set AnaDosya = ThisWorkbook

YeniStoryBoard.Sheets("Storyboard").Copy After:=ThisWorkbook.Sheets("Kunye")  '-> This gives error

YeniStoryBoard.Close

Set YeniStoryBoard_isim = Sheets("Storyboard")
YeniStoryBoard_isim.Name = "StoryboardXXYYZZ"


   End With
End Sub

我将对代码进行一些修改,但这不能正常工作。 :(

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

以下是解决您案件的单行代码:

Public Sub TestMe
    ThisWorkbook.Worksheets("Storyboard").copy after:= ThisWorkbook.Worksheets("Kunye")
End Sub

它应该工作。然后逐行开始检查在您的案例中不起作用的内容。我想问题是在Dim YeniStoryBoard As Workbook之后你没有设置它。因此,它是Nothing