gpt4 book ai didi

vba - 复制和粘贴 Excel 工作表

转载 作者:行者123 更新时间:2023-12-04 20:13:04 27 4
gpt4 key购买 nike

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 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(扩展名为 .xls,例如 Excel 97 或 Excel 2003),则旧工作表中的行数限制为 2^16-1,因为行号编码为 16 位.在较新的版本中,此数字以 32 位编码。

因此,将新版本的工作表“作为一个整体”复制到旧版本的工作簿中会引发此错误。根据我的测试,即使复制的工作表中实际使用的范围很小,也会发生此错误。

关于vba - 复制和粘贴 Excel 工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33530460/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com