我和VBA和Excel宏全新的,我想要做简单说就是:VBA切片复制方法
我想,一旦我在切片机点击数据,它会自动被复制在剪贴板中。
我切片名称是:Slicer_Internal_Punter_ID
请让我知道,如果你还需要其他信息。我认为这很容易,但我现在要疯了。
谢谢。我很乐意欣赏它。
,这里是切片机的详细信息
我和VBA和Excel宏全新的,我想要做简单说就是:VBA切片复制方法
我想,一旦我在切片机点击数据,它会自动被复制在剪贴板中。
我切片名称是:Slicer_Internal_Punter_ID
请让我知道,如果你还需要其他信息。我认为这很容易,但我现在要疯了。
谢谢。我很乐意欣赏它。
,这里是切片机的详细信息
您可以使用以下过程和事件来获取所选项目的名称。
将此过程添加到任何模块,并使用立即窗口(查看/立即窗口)读取并复制SliceCache的正确名称。它需要在其他片段中使用。
Sub GetSlicerData()
'## Variables ##
Dim iSlicerCache As SlicerCache 'Slicer Cache Object
Dim iSlicerItem As SlicerItem 'Slicer Item
Dim iSlicer As Slicer 'Slicer Object
'## Looping through Slicer Caches in 'ThisWorkbook' ##
For Each slSlicerCache In ThisWorkbook.SlicerCaches
Debug.Print ("Slicer Cache Namee: " & slSlicerCache.Name) 'Printing the name property of the SlicerCaches
'## Looping through Slicers contained in the SlicerCaches ##
For Each iSlicer In slSlicerCache.Slicers
Debug.Print ("Slicer Name: " & iSlicer.Name) 'Printing the slicer names
Next iSlicer
'## Looping through Items contained in the SlicerCaches ##
'and testing selection status
For Each iSlicerItem In slSlicerCache.SlicerItems
If iSlicerItem.Selected = True Then Debug.Print ("Selected Item: " & iSlicerItem.Name) 'Printing the slicer items
Next iSlicerItem
Next slSlicerCache
End Sub
第二个片段是一个工作表事件,必须将其添加到受分割器影响的工作表中。
该板在宏编辑器(项目资源管理器窗口)上双击添加代码: Adding the Event to the sheet
第二个片段将打印所选项目的直接窗口。
Private Sub Worksheet_Change(ByVal Target As Range)
'Debug.Print ("Sheet name: " & Me.Name) 'Sheet name
'## Looping through Slicer Caches in 'ThisWorkbook' ##
Dim slcSlicerCache As SlicerCache 'Slicer Cache Object
Dim iSlicerItem As SlicerItem 'Slicer Item
Dim stItems As String
'## Setting slicer cache ##
'Replace with the correct name: "Slicer_Internal_Punter_ID"
Set slcSlicerCache = ThisWorkbook.SlicerCaches("Slicer_Internal_Punter_ID")
For Each iSlicerItem In slcSlicerCache.SlicerItems
If iSlicerItem.Selected = True Then
Debug.Print ("Selected Item: " & iSlicerItem.Name) 'Printing selected
If Len(stItems) = 0 Then stItems = iSlicerItem.Name Else stItems = stItems & vbNewLine & iSlicerItem.Name
End If
Next iSlicerItem
Debug.Print ("Selected Items: " & vbNewLine & stItems) 'Printing selected
'ADD CODE HERE: moving content to clipboard
End Sub
请注意在此行中使用切片机的正确名称:
Set slcSlicerCache = ThisWorkbook.SlicerCaches("Slicer_Internal_Punter_ID")
另外发布的项目名称到剪贴板,你可以查看以下链接:How to copy text to clipboard
ILL尝试此操作。谢谢 :-) –
本网站不是免费的编码服务。如果你是VBA新手,你可能需要从一些不太复杂的事情开始。 – teylyn
好吧,还是谢谢你。 –