Private Sub CommandButton1_Click()
Dim ws As Worksheet
With Application.FileDialog(msoFileDialogFilePicker)
.Show
If .SelectedItems.Count <> 0 Then
fldr = .SelectedItems(1)
End If
End With
Sheets.link.Value = fldr
For i = 1 To Worksheets.Count
Set ws = Worksheets(i)
If ws.Cells(2, 1) = "X" Then
Sheets.ComboBox1.AddItem (ws.Name)
End If
Next i
Workbooks.Open (fldr)
Sheets.Show
End Sub
Private Sub Add_Click()
Dim x As String
Dim ws As Workbook
x = Right(link.Value, (Len(link.Value) - InStrRev(link.Value, "ild") - 3))
Workbooks("Test.xlsm").Activate
Worksheets(ComboBox1.Value).Copy Before:=Workbooks(x).Worksheets("Contract")
End Sub
所以基本的想法是,您单击Excel工作表上的按钮。用户然后找到他们想要复制表单的文件。它会查找所有特定类型的工作表,将其放在表单组合框中并打开选定的Excel文件。 然后您从组合框中选择一张工作表并将其从一个工作簿复制到另一个工作簿。它一直运行直到复制部分。我弄了半天错误:复制并粘贴Excel工作表
Excel cannot insert the sheets into the destination workbook, because it contains fewer rows and columns that the source workbook. To move or copy the data to the destination workbook, you can select the data and then use Copy and Paste commands to insert it into the sheets of another workbook.
首先想到的是,源工作表可能太大,而目标工作簿来自旧版本的Excel。是对的吗? –
在答案部分放一些东西,所以我也可以接受,因为你是对的。我使用和.xlsm,而我正在复制的是.xls。当我将它保存为.xlsm时,它工作正常。 – Chris
我很高兴它有帮助。好吧,别担心,重要的是问题解决了。感谢你的好意无论如何;) –