回答編集履歴
1
改良版
answer
CHANGED
@@ -43,4 +43,129 @@
|
|
43
43
|
End With
|
44
44
|
End Sub
|
45
45
|
|
46
|
+
```
|
47
|
+
---
|
48
|
+
改良版です。
|
49
|
+
2パターン作ってみました。
|
50
|
+
1つ目は前回の改良版です。
|
51
|
+
クリックしたテキストボックスの横に吹き出し図形を作成します。
|
52
|
+
2つ目は、テキストボックスの位置のセルにコメントを追加して、それを表示させています。
|
53
|
+
どちらも5秒後に自動的に消えます。
|
54
|
+
また再クリックで即削除します。
|
55
|
+
test関数を実行すると、B2セルの値でC2セルの位置にパターン1のテキストボックスを、
|
56
|
+
B4セルの値でC4セルの位置にパターン2のテキストボックスを作成します。
|
57
|
+
いずれも無理やり感は否めません…。
|
58
|
+
```VBA
|
59
|
+
' API定義
|
60
|
+
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
|
61
|
+
|
62
|
+
Sub test()
|
63
|
+
Dim fc As Range
|
64
|
+
Dim tc As Range
|
65
|
+
|
66
|
+
' 吹き出しを作成するパターン
|
67
|
+
With ActiveSheet
|
68
|
+
Set fc = .Range("B2")
|
69
|
+
Set tc = .Range("C2")
|
70
|
+
With .Shapes.AddShape(msoShapeRectangle, tc.Left, tc.Top, tc.Width, tc.Height)
|
71
|
+
.TextFrame.Characters.Text = fc.Value
|
72
|
+
' クリック時に呼び出す関数を登録
|
73
|
+
.OnAction = "'text_OnClick""" & .Name & """'"
|
74
|
+
End With
|
75
|
+
End With
|
76
|
+
|
77
|
+
' テキストボックスの裏のセルにコメントを作成するパターン
|
78
|
+
With ActiveSheet
|
79
|
+
Set fc = .Range("B4")
|
80
|
+
Set tc = .Range("C4")
|
81
|
+
With .Shapes.AddShape(msoShapeRectangle, tc.Left, tc.Top, tc.Width, tc.Height)
|
82
|
+
.TextFrame.Characters.Text = fc.Value
|
83
|
+
' クリック時に呼び出す関数を登録
|
84
|
+
.OnAction = "'text_OnClick2""" & .Name & "," & "C4" & """'"
|
85
|
+
End With
|
86
|
+
End With
|
87
|
+
|
88
|
+
End Sub
|
89
|
+
|
90
|
+
Sub text_OnClick(nm As String)
|
91
|
+
|
92
|
+
Static fnm As String ' 吹き出しNAME
|
93
|
+
Static nms As String
|
94
|
+
Dim s As Shape
|
95
|
+
|
96
|
+
If nm = nms Then
|
97
|
+
GoTo ENDPROC
|
98
|
+
End If
|
99
|
+
nms = nm
|
100
|
+
|
101
|
+
With ActiveSheet
|
102
|
+
x = .Shapes(nm).Left
|
103
|
+
y = .Shapes(nm).Top
|
104
|
+
w = .Shapes(nm).Width
|
105
|
+
h = .Shapes(nm).Height
|
106
|
+
End With
|
107
|
+
|
108
|
+
' 吹き出しを作成
|
109
|
+
With ActiveSheet.Shapes.AddShape(msoShapeBalloon, x + w + 10, y - h, 100, 100)
|
110
|
+
.TextFrame.Characters.Text = ActiveSheet.Shapes(nm).TextFrame.Characters.Text
|
111
|
+
fnm = .Name
|
112
|
+
End With
|
113
|
+
|
114
|
+
' 5秒ウェイト
|
115
|
+
For i = 1 To 50
|
116
|
+
Sleep 100
|
117
|
+
DoEvents
|
118
|
+
Next
|
119
|
+
|
120
|
+
ENDPROC:
|
121
|
+
' 吹き出しを削除
|
122
|
+
For Each s In ActiveSheet.Shapes
|
123
|
+
If s.Name = fnm Then
|
124
|
+
s.Delete
|
125
|
+
End If
|
126
|
+
Next
|
127
|
+
nms = ""
|
128
|
+
|
129
|
+
End Sub
|
130
|
+
|
131
|
+
Sub text_OnClick2(param As String)
|
132
|
+
|
133
|
+
Dim pa() As String
|
134
|
+
Dim nm As String
|
135
|
+
Static nms As String
|
136
|
+
Static xy As String
|
137
|
+
|
138
|
+
pa = Split(param, ",")
|
139
|
+
nm = pa(0)
|
140
|
+
xy = pa(1)
|
141
|
+
|
142
|
+
If pa(0) = nms Then
|
143
|
+
GoTo ENDPROC
|
144
|
+
End If
|
145
|
+
nms = nm
|
146
|
+
|
147
|
+
|
148
|
+
With ActiveSheet
|
149
|
+
.Range(xy).AddComment (.Shapes(nms).TextFrame.Characters.Text)
|
150
|
+
.Range(xy).Comment.Visible = True
|
151
|
+
End With
|
152
|
+
|
153
|
+
' 5秒ウェイト
|
154
|
+
For i = 1 To 50
|
155
|
+
Sleep 100
|
156
|
+
DoEvents
|
157
|
+
Next
|
158
|
+
|
159
|
+
ENDPROC:
|
160
|
+
' コメントを削除
|
161
|
+
With ActiveSheet
|
162
|
+
If Not .Range(xy).Comment Is Nothing Then
|
163
|
+
.Range(xy).Comment.Delete
|
164
|
+
End If
|
165
|
+
End With
|
166
|
+
nms = ""
|
167
|
+
|
168
|
+
End Sub
|
169
|
+
|
170
|
+
|
46
171
|
```
|