Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. Option Explicit
  2.  
  3. ''' ******************使い方**********************************
  4. ''' 「Microsoft Forms 2.0 Object Library」を参照設定します。
  5. ''' **********************************************************
  6. Sub コピーEX()
  7. 'ワーク初期化
  8. Dim コピーEX_Work() As Variant
  9. ReDim コピーEX_Work(Selection.Rows.Count - 1)
  10.  
  11. Dim arrayCount As Long
  12. Dim idx As Long
  13. arrayCount = 0
  14. idx = 0
  15. '配列にセルの内容を貯め込む
  16. For idx = Selection(1).row To Selection(Selection.Count).row
  17. ''コピペ用セル値を貯め込む
  18. コピーEX_Work(arrayCount) = Cells(idx, Selection(1).Column).Value
  19. arrayCount = arrayCount + 1
  20. Next idx
  21.  
  22. '配列からクリップボード用テキスト作成
  23. Dim text As String
  24. Dim i As Integer
  25. For i = 0 To UBound(コピーEX_Work)
  26. text = text + CStr(コピーEX_Work(i)) + vbCrLf
  27. Next i
  28.  
  29. 'クリップボードに送る
  30. With New MSForms.DataObject
  31. .SetText text '変数の値をDataObjectに格納する
  32. .PutInClipboard 'DataObjectのデータをクリップボードに格納する
  33. End With
  34.  
  35. End Sub
  36.  
  37. Sub 貼り付けEX()
  38.  
  39. Dim cbFormat As Variant
  40. Dim clipText As String
  41. With New MSForms.DataObject
  42. .GetFromClipboard ''変数のデータをDataObjectに格納する
  43.  
  44. cbFormat = Application.ClipboardFormats
  45. If cbFormat(1) <> 0 Then
  46. MsgBox "クリップボードにテキストが入っていません"
  47. Exit Sub
  48. End If
  49.  
  50. clipText = .GetText
  51. End With
  52.  
  53. Dim arr As Variant
  54. arr = Split(clipText, vbCrLf)
  55. ReDim Preserve arr(UBound(arr) - 1) '余計な改行分削除
  56.  
  57. 'アクティブセル取得
  58. Dim ac As Range
  59. Set ac = Selection(1)
  60. Dim idx As Long
  61. idx = 0
  62. For idx = 0 To UBound(arr)
  63. ac.Offset(idx, 0).Value = arr(idx)
  64. Next idx
  65.  
  66. End Sub
  67.  
  68.  
  69. Sub クリップボードモード切り替え()
  70. Static mode As Boolean
  71. mode = Not mode
  72. If mode Then
  73. Application.StatusBar = "★拡張クリップボードモード---- 【コピー:F3】 【貼り付け:F4】"
  74. Application.OnKey "{F3}", "コピーEX"
  75. Application.OnKey "{F4}", "貼り付けEX"
  76. Else
  77. Application.StatusBar = ""
  78. Application.OnKey "{F3}", ""
  79. Application.OnKey "{F4}", ""
  80. End If
  81. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement