我有以下腳本將活動單元格的范圍復制到剪貼板,它作業正常,直到我保存檔案(不關閉它),之后它會中斷:
Sub getCellSheetAndAddress()
Dim Sheet As String
Dim Address As String
Dim myData As DataObject
Sheet = ActiveSheet.Name
Address = ActiveCell.Address
Set myData = New DataObject
myData.SetText (Sheet "!" Address)
myData.PutInClipboard
Set myData = Nothing
End Sub
我可以使用這個宏來獲取單元格范圍然后粘貼它,但是當我保存 excel 并再次運行宏時,粘貼到單元格中的是兩個空白方塊而不是單元格位置。
其背后的原因是什么以及如何解決?
非常感謝
uj5u.com熱心網友回復:
您可以使用如下函式:
Function SetClipBoardText(ByVal Text As Variant) As Boolean
CreateObject("htmlfile").ParentWindow.ClipboardData.SetData "Text", Text
End Function
Function GetClipBoardText() As String
On Error Resume Next
GetClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.getData("Text")
End Function
或查看SetClipBoardData和GetClipBoardDataAPI 函式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/518026.html
標籤:擅长vba节省
