回答編集履歴
1
改良版
test
CHANGED
@@ -89,3 +89,253 @@
|
|
89
89
|
|
90
90
|
|
91
91
|
```
|
92
|
+
|
93
|
+
---
|
94
|
+
|
95
|
+
改良版です。
|
96
|
+
|
97
|
+
2パターン作ってみました。
|
98
|
+
|
99
|
+
1つ目は前回の改良版です。
|
100
|
+
|
101
|
+
クリックしたテキストボックスの横に吹き出し図形を作成します。
|
102
|
+
|
103
|
+
2つ目は、テキストボックスの位置のセルにコメントを追加して、それを表示させています。
|
104
|
+
|
105
|
+
どちらも5秒後に自動的に消えます。
|
106
|
+
|
107
|
+
また再クリックで即削除します。
|
108
|
+
|
109
|
+
test関数を実行すると、B2セルの値でC2セルの位置にパターン1のテキストボックスを、
|
110
|
+
|
111
|
+
B4セルの値でC4セルの位置にパターン2のテキストボックスを作成します。
|
112
|
+
|
113
|
+
いずれも無理やり感は否めません…。
|
114
|
+
|
115
|
+
```VBA
|
116
|
+
|
117
|
+
' API定義
|
118
|
+
|
119
|
+
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
Sub test()
|
124
|
+
|
125
|
+
Dim fc As Range
|
126
|
+
|
127
|
+
Dim tc As Range
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
' 吹き出しを作成するパターン
|
132
|
+
|
133
|
+
With ActiveSheet
|
134
|
+
|
135
|
+
Set fc = .Range("B2")
|
136
|
+
|
137
|
+
Set tc = .Range("C2")
|
138
|
+
|
139
|
+
With .Shapes.AddShape(msoShapeRectangle, tc.Left, tc.Top, tc.Width, tc.Height)
|
140
|
+
|
141
|
+
.TextFrame.Characters.Text = fc.Value
|
142
|
+
|
143
|
+
' クリック時に呼び出す関数を登録
|
144
|
+
|
145
|
+
.OnAction = "'text_OnClick""" & .Name & """'"
|
146
|
+
|
147
|
+
End With
|
148
|
+
|
149
|
+
End With
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
' テキストボックスの裏のセルにコメントを作成するパターン
|
154
|
+
|
155
|
+
With ActiveSheet
|
156
|
+
|
157
|
+
Set fc = .Range("B4")
|
158
|
+
|
159
|
+
Set tc = .Range("C4")
|
160
|
+
|
161
|
+
With .Shapes.AddShape(msoShapeRectangle, tc.Left, tc.Top, tc.Width, tc.Height)
|
162
|
+
|
163
|
+
.TextFrame.Characters.Text = fc.Value
|
164
|
+
|
165
|
+
' クリック時に呼び出す関数を登録
|
166
|
+
|
167
|
+
.OnAction = "'text_OnClick2""" & .Name & "," & "C4" & """'"
|
168
|
+
|
169
|
+
End With
|
170
|
+
|
171
|
+
End With
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
End Sub
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
Sub text_OnClick(nm As String)
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
Static fnm As String ' 吹き出しNAME
|
184
|
+
|
185
|
+
Static nms As String
|
186
|
+
|
187
|
+
Dim s As Shape
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
If nm = nms Then
|
192
|
+
|
193
|
+
GoTo ENDPROC
|
194
|
+
|
195
|
+
End If
|
196
|
+
|
197
|
+
nms = nm
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
With ActiveSheet
|
202
|
+
|
203
|
+
x = .Shapes(nm).Left
|
204
|
+
|
205
|
+
y = .Shapes(nm).Top
|
206
|
+
|
207
|
+
w = .Shapes(nm).Width
|
208
|
+
|
209
|
+
h = .Shapes(nm).Height
|
210
|
+
|
211
|
+
End With
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
' 吹き出しを作成
|
216
|
+
|
217
|
+
With ActiveSheet.Shapes.AddShape(msoShapeBalloon, x + w + 10, y - h, 100, 100)
|
218
|
+
|
219
|
+
.TextFrame.Characters.Text = ActiveSheet.Shapes(nm).TextFrame.Characters.Text
|
220
|
+
|
221
|
+
fnm = .Name
|
222
|
+
|
223
|
+
End With
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
' 5秒ウェイト
|
228
|
+
|
229
|
+
For i = 1 To 50
|
230
|
+
|
231
|
+
Sleep 100
|
232
|
+
|
233
|
+
DoEvents
|
234
|
+
|
235
|
+
Next
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
ENDPROC:
|
240
|
+
|
241
|
+
' 吹き出しを削除
|
242
|
+
|
243
|
+
For Each s In ActiveSheet.Shapes
|
244
|
+
|
245
|
+
If s.Name = fnm Then
|
246
|
+
|
247
|
+
s.Delete
|
248
|
+
|
249
|
+
End If
|
250
|
+
|
251
|
+
Next
|
252
|
+
|
253
|
+
nms = ""
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
End Sub
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
Sub text_OnClick2(param As String)
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
Dim pa() As String
|
266
|
+
|
267
|
+
Dim nm As String
|
268
|
+
|
269
|
+
Static nms As String
|
270
|
+
|
271
|
+
Static xy As String
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
pa = Split(param, ",")
|
276
|
+
|
277
|
+
nm = pa(0)
|
278
|
+
|
279
|
+
xy = pa(1)
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
If pa(0) = nms Then
|
284
|
+
|
285
|
+
GoTo ENDPROC
|
286
|
+
|
287
|
+
End If
|
288
|
+
|
289
|
+
nms = nm
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
With ActiveSheet
|
296
|
+
|
297
|
+
.Range(xy).AddComment (.Shapes(nms).TextFrame.Characters.Text)
|
298
|
+
|
299
|
+
.Range(xy).Comment.Visible = True
|
300
|
+
|
301
|
+
End With
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
' 5秒ウェイト
|
306
|
+
|
307
|
+
For i = 1 To 50
|
308
|
+
|
309
|
+
Sleep 100
|
310
|
+
|
311
|
+
DoEvents
|
312
|
+
|
313
|
+
Next
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
ENDPROC:
|
318
|
+
|
319
|
+
' コメントを削除
|
320
|
+
|
321
|
+
With ActiveSheet
|
322
|
+
|
323
|
+
If Not .Range(xy).Comment Is Nothing Then
|
324
|
+
|
325
|
+
.Range(xy).Comment.Delete
|
326
|
+
|
327
|
+
End If
|
328
|
+
|
329
|
+
End With
|
330
|
+
|
331
|
+
nms = ""
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
End Sub
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
```
|