我正在从具有复选框的模板中复制数据,我不知道如何复制复选框,但我想将数据和复选框复制到我的工作簿中。我希望复选框保持在模板中的确切位置。
这是我对数据的复制:
Workbooks.Open Filename:="C:\myexcel.xlsm"
Application.DisplayAlerts = False
Workbooks("copysheet.xlsm").Activate
Workbooks("copysheet.xlsm").Sheet("mysheet").Rows("1").select
Selection.Copy
Workbooks("currentsheet.xlsm").Activate
Workbooks("copysheet.xlsm").Sheet("mycurrentsheet").Rows("1").select
ActiveSheet.Paste
答案 0 :(得分:0)
复制数据应该不是问题,就复制复选框而言,您可以使用以下功能
Private Sub CopyCheckBoxes()
Dim fromSheet As Worksheet
Dim toSheet As Worksheet
Dim chk As CheckBox
Set fromSheet = Workbooks("Book1").Worksheets("Sheet1")
Set toSheet = Workbooks("Book3").Worksheets("Sheet1")
For Each Item In fromSheet.OLEObjects
If Item.progID = "Forms.CheckBox.1" Then
toSheet.OLEObjects.Add("Forms.CheckBox.1", Left:=Item.Left, Top:=Item.Top, Width:=Item.Width, Height:=Item.Height).Select
With Selection
.Name = Item.Name
.Object.Value = Item.Object.Value
.Object.Caption = Item.Object.Caption
End With
End If
Next
End Sub