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
我很高興它有幫助。好吧,別擔心,重要的是問題解決了。感謝你的好意無論如何;) –