質問編集履歴

6

更新

2019/06/07 07:29

投稿

saku88
saku88

スコア11

test CHANGED
File without changes
test CHANGED
@@ -20,286 +20,276 @@
20
20
 
21
21
  ```VBA
22
22
 
23
- Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl
23
+ Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl
24
-
24
+
25
- Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
25
+ Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
26
-
26
+
27
- Dim cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl
27
+ Dim cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl
28
-
28
+
29
- Dim cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
29
+ Dim cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
30
+
31
+
32
+
33
+ Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
34
+
35
+
36
+
37
+ If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then
38
+
39
+   '以下で、新規のメニューを追加
40
+
41
+  Set cmdBra1 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
42
+
43
+   With cmdBra1
44
+
45
+    .Caption = "▽野菜▽" 'グループメニュー名
46
+
47
+   End With
48
+
49
+  Set cmdBra2 = cmdBra1.Controls.Add()
50
+
51
+   With cmdBra2
52
+
53
+    .Caption = "胡瓜" 'メニュー表示名
54
+
55
+    .FaceId = 2
56
+
57
+    .OnAction = "胡瓜" '実行するマクロ名
58
+
59
+   End With
60
+
61
+ Set cmdBra2 = cmdBra1.Controls.Add()
62
+
63
+   With cmdBra2
64
+
65
+    .Caption = "白菜"
66
+
67
+    .FaceId = 2
68
+
69
+    .OnAction = "白菜"
70
+
71
+   End With
72
+
73
+ Set cmdBra2 = cmdBra1.Controls.Add()
74
+
75
+   With cmdBra2
76
+
77
+    .Caption = "キャベツ"
78
+
79
+    .FaceId = 2
80
+
81
+    .OnAction = "キャベツ"
82
+
83
+   End With
84
+
85
+   End If
86
+
87
+
88
+
89
+ If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
90
+
91
+ Set cmdBra3 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
92
+
93
+   With cmdBra3
94
+
95
+    .Caption = "▽果物▽"
96
+
97
+   End With
98
+
99
+ Set cmdBra4 = cmdBra3.Controls.Add()
100
+
101
+ With cmdBra4
102
+
103
+ .Caption = "苺"
104
+
105
+ .FaceId = 2
106
+
107
+ .OnAction = "苺"
108
+
109
+ End With
110
+
111
+ Set cmdBra4 = cmdBra3.Controls.Add()
112
+
113
+ With cmdBra4
114
+
115
+ .Caption = "リンゴ"
116
+
117
+ .FaceId = 2
118
+
119
+ .OnAction = "リンゴ"
120
+
121
+ End With
122
+
123
+ Set cmdBra4 = cmdBra3.Controls.Add()
124
+
125
+ With cmdBra4
126
+
127
+ .Caption = "バナナ"
128
+
129
+ .FaceId = 2
130
+
131
+ .OnAction = "バナナ"
132
+
133
+ End With
134
+
135
+ End If
136
+
137
+
138
+
139
+ If Not Application.Intersect(Target, Range("C:C")) Is Nothing Then
140
+
141
+ Set cmdBra5 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
142
+
143
+ With cmdBra5
144
+
145
+ .Caption = "▽精肉▽"
146
+
147
+ End With
148
+
149
+ Set cmdBra6 = cmdBra5.Controls.Add()
150
+
151
+ With cmdBra6
152
+
153
+ .Caption = "豚肉"
154
+
155
+ .FaceId = 2
156
+
157
+ .OnAction = "豚肉"
158
+
159
+ End With
160
+
161
+ Set cmdBra6 = cmdBra5.Controls.Add()
162
+
163
+ With cmdBra6
164
+
165
+ .Caption = "牛肉"
166
+
167
+ .FaceId = 2
168
+
169
+ .OnAction = "牛肉"
170
+
171
+ End With
172
+
173
+ Set cmdBra6 = cmdBra5.Controls.Add()
174
+
175
+ With cmdBra6
176
+
177
+ .Caption = "鶏肉"
178
+
179
+ .FaceId = 2
180
+
181
+ .OnAction = "鶏肉"
182
+
183
+ End With
184
+
185
+
186
+
187
+ Set cmdBra7 = Application.CommandBars("Cell").Controls.Add(Before:=2, Type:=msoControlPopup)
188
+
189
+ With cmdBra7
190
+
191
+ .Caption = "▼鮮魚▼"
192
+
193
+ End With
194
+
195
+ Set cmdBra8 = cmdBra7.Controls.Add()
196
+
197
+ With cmdBra8
198
+
199
+ .Caption = "鮭"
200
+
201
+ .FaceId = 2
202
+
203
+ .OnAction = "鮭"
204
+
205
+ End With
206
+
207
+ Set cmdBra8 = cmdBra7.Controls.Add()
208
+
209
+ With cmdBra8
210
+
211
+ .Caption = "鯖"
212
+
213
+ .FaceId = 2
214
+
215
+ .OnAction = "鯖"
216
+
217
+ End With
218
+
219
+ Set cmdBra8 = cmdBra7.Controls.Add()
220
+
221
+ With cmdBra8
222
+
223
+ .Caption = "秋刀魚"
224
+
225
+ .FaceId = 2
226
+
227
+ .OnAction = "秋刀魚"
228
+
229
+ End With
230
+
231
+ End If
232
+
233
+
234
+
235
+ Application.CommandBars("Cell").ShowPopup
236
+
237
+ Application.CommandBars("Cell").Reset
238
+
239
+ Cancel = True
240
+
241
+ End Sub```
242
+
243
+
244
+
245
+ ```
246
+
247
+ ```別VBA
248
+
249
+ Dim cmdBar As CommandBar, cmdBarc1 As CommandBarControl
250
+
251
+ Dim cmdBarc2 As CommandBarControl
30
252
 
31
253
 
32
254
 
33
255
  Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
34
256
 
35
-
36
-
37
- If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then
38
-
39
- '以下で、新規のメニューを追加
40
-
41
-
42
-
43
- Set cmdBra1 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
44
-
45
- With cmdBra1
46
-
47
- .Caption = "▽野菜▽" 'グループメニュー名
48
-
49
- End With
50
-
51
-
52
-
53
- Set cmdBra2 = cmdBra1.Controls.Add()
54
-
55
- With cmdBra2
56
-
57
- .Caption = "胡瓜" 'メニュー表示名
58
-
59
- .FaceId = 2
60
-
61
- .OnAction = "胡瓜" '実行するマクロ名
62
-
63
- End With
64
-
65
-
66
-
67
- Set cmdBra2 = cmdBra1.Controls.Add()
68
-
69
- With cmdBra2
70
-
71
- .Caption = "白菜"
72
-
73
- .FaceId = 2
74
-
75
- .OnAction = "白菜"
76
-
77
- End With
78
-
79
-
80
-
81
- Set cmdBra2 = cmdBra1.Controls.Add()
82
-
83
- With cmdBra2
84
-
85
- .Caption = "キャベツ"
86
-
87
- .FaceId = 2
88
-
89
- .OnAction = "キャベツ"
90
-
91
- End With
92
-
93
- End If
94
-
95
-
96
-
97
- If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
98
-
99
-
100
-
101
- Set cmdBra3 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
102
-
103
- With cmdBra3
104
-
105
- .Caption = "▽果物▽"
106
-
107
- End With
108
-
109
-
110
-
111
- Set cmdBra4 = cmdBra3.Controls.Add()
112
-
113
- With cmdBra4
114
-
115
- .Caption = "苺"
116
-
117
- .FaceId = 2
118
-
119
- .OnAction = "苺"
120
-
121
- End With
122
-
123
- Set cmdBra4 = cmdBra3.Controls.Add()
124
-
125
- With cmdBra4
126
-
127
- .Caption = "リンゴ"
128
-
129
- .FaceId = 2
130
-
131
- .OnAction = "リンゴ"
132
-
133
- End With
134
-
135
- Set cmdBra4 = cmdBra3.Controls.Add()
136
-
137
- With cmdBra4
138
-
139
- .Caption = "バナナ"
140
-
141
- .FaceId = 2
142
-
143
- .OnAction = "バナナ"
144
-
145
- End With
146
-
147
- End If
148
-
149
- If Not Application.Intersect(Target, Range("C:C")) Is Nothing Then
150
-
151
- Set cmdBra5 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
152
-
153
- With cmdBra5
154
-
155
- .Caption = "▽精肉▽"
156
-
157
- End With
158
-
159
- Set cmdBra6 = cmdBra5.Controls.Add()
160
-
161
- With cmdBra6
162
-
163
- .Caption = "豚肉"
164
-
165
- .FaceId = 2
166
-
167
- .OnAction = "豚肉"
168
-
169
- End With
170
-
171
- Set cmdBra6 = cmdBra5.Controls.Add()
172
-
173
- With cmdBra6
174
-
175
- .Caption = "牛肉"
176
-
177
- .FaceId = 2
178
-
179
- .OnAction = "牛肉"
180
-
181
- End With
182
-
183
- Set cmdBra6 = cmdBra5.Controls.Add()
184
-
185
- With cmdBra6
186
-
187
- .Caption = "鶏肉"
188
-
189
- .FaceId = 2
190
-
191
- .OnAction = "鶏肉"
192
-
193
- End With
194
-
195
-
196
-
197
- Set cmdBra7 = Application.CommandBars("Cell").Controls.Add(Before:=2, Type:=msoControlPopup)
198
-
199
- With cmdBra7
200
-
201
- .Caption = "▼鮮魚▼"
202
-
203
- End With
204
-
205
- Set cmdBra8 = cmdBra7.Controls.Add()
206
-
207
- With cmdBra8
208
-
209
- .Caption = "鮭"
210
-
211
- .FaceId = 2
212
-
213
- .OnAction = "鮭"
214
-
215
- End With
216
-
217
- Set cmdBra8 = cmdBra7.Controls.Add()
218
-
219
- With cmdBra8
220
-
221
- .Caption = "鯖"
222
-
223
- .FaceId = 2
224
-
225
- .OnAction = "鯖"
226
-
227
- End With
228
-
229
- Set cmdBra8 = cmdBra7.Controls.Add()
230
-
231
- With cmdBra8
232
-
233
- .Caption = "秋刀魚"
234
-
235
- .FaceId = 2
236
-
237
- .OnAction = "秋刀魚"
238
-
239
- End With
240
-
241
- End If
242
-
243
- Application.CommandBars("Cell").ShowPopup
244
-
245
- Application.CommandBars("Cell").Reset
246
-
247
- Cancel = True
248
-
249
- End Sub```
250
-
251
-
257
+ If Not Application.Intersect(Target, Range("I:I")) Is Nothing Then
258
+
259
+ Set cmdBar = Application.CommandBars("Cell")
260
+
261
+ Set cmdBarc1 = cmdBar.Controls.Add(Before:=1, Type:=msoControlPopup)
262
+
263
+ With cmdBarc1
264
+
265
+ .Caption = "▽野菜▽"
266
+
267
+ With .Controls.Add
268
+
269
+ .Caption = "胡瓜"
270
+
271
+ .OnAction = "胡瓜"
272
+
273
+ End With
274
+
275
+ With .Controls.Add
276
+
277
+ .Caption = "白菜"
278
+
279
+ .OnAction = "白菜"
280
+
281
+ End With
282
+
283
+ End IF・・・以下同文``````
284
+
285
+
286
+
287
+ 上記のVBAだとEnd Ifが不要とのエラーになり、最初の「野菜」メニューしか表示されません
252
288
 
253
289
 
254
290
 
255
291
  ``````
256
292
 
257
- ```別VBA
258
-
259
- Dim cmdBar As CommandBar, cmdBarc1 As CommandBarControl
260
-
261
- Dim cmdBarc2 As CommandBarControl
262
-
263
-
264
-
265
- Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
266
-
267
- If Not Application.Intersect(Target, Range("I:I")) Is Nothing Then
268
-
269
- Set cmdBar = Application.CommandBars("Cell")
270
-
271
- Set cmdBarc1 = cmdBar.Controls.Add(Before:=1, Type:=msoControlPopup)
272
-
273
- With cmdBarc1
274
-
275
- .Caption = "▽野菜▽"
276
-
277
- With .Controls.Add
278
-
279
- .Caption = "胡瓜"
280
-
281
- .OnAction = "胡瓜"
282
-
283
- End With
284
-
285
- With .Controls.Add
286
-
287
- .Caption = "白菜"
288
-
289
- .OnAction = "白菜"
290
-
291
- End With
292
-
293
- End IF・・・以下同文``````
294
-
295
-
296
-
297
- 上記のVBAだとEnd Ifが不要とのエラーになり、最初の「野菜」メニューしか表示されません
298
-
299
-
300
-
301
- ``````
302
-
303
293
  ### 試したこと
304
294
 
305
295
 

5

できました・・

2019/06/07 07:29

投稿

saku88
saku88

スコア11

test CHANGED
File without changes
test CHANGED
@@ -16,257 +16,243 @@
16
16
 
17
17
 
18
18
 
19
+ ```ここに言語を入力
20
+
19
- ```VBA
21
+ ```VBA
20
-
22
+
21
- Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl
23
+ Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl
22
-
24
+
23
- Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
25
+ Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
24
-
26
+
25
- Dim cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl
27
+ Dim cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl
26
-
28
+
27
- Dim cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
29
+ Dim cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
28
-
29
-
30
-
30
+
31
+
32
+
31
- Private Sub Worksheet_BeforeRightClick(**ByVal** Target As Range, Cancel As **Boolean**)
33
+ Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
32
-
33
-
34
-
34
+
35
+
36
+
35
- If Not Application.Intersect(Target, Range("__A:A__")) Is Nothing Then
37
+ If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then
36
-
38
+
37
- '以下で、新規のメニューを追加
39
+ '以下で、新規のメニューを追加
38
-
40
+
41
+
42
+
39
- Set cmdBra1 = Application.CommandBars("__Cell__").Controls.Add(Before:=1, Type:=msoControlPopup)
43
+ Set cmdBra1 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
40
-
44
+
41
-  ###### With cmdBra1
45
+ With cmdBra1
42
-
46
+
43
-   .Caption = **"▽野菜▽" **'グループメニュー名    **> A列に大分類「野菜を表示」その中に胡瓜等小分類を入れてます**
47
+ .Caption = "▽野菜▽" 'グループメニュー名
44
-
48
+
45
-   End With
49
+ End With
46
-
47
-
48
-
49
- Set cmdBra2 = cmdBra1.Controls.Add()
50
-
51
-   With cmdBra2
52
-
53
-    .Caption = **"胡瓜"** 'メニュー表示名
54
-
55
-    .FaceId = 2
56
-
57
-    .OnAction = **"胡瓜"** '実行するマクロ名
58
-
59
-   End With
60
50
 
61
51
 
62
52
 
63
53
  Set cmdBra2 = cmdBra1.Controls.Add()
64
54
 
65
-   With cmdBra2
55
+ With cmdBra2
66
-
56
+
67
-    .Caption = **"白菜"**
57
+ .Caption = "胡瓜" 'メニュー表示名
68
-
58
+
69
-    .FaceId = 2
59
+ .FaceId = 2
70
-
60
+
71
-    .OnAction = **"白菜"**
61
+ .OnAction = "胡瓜" '実行するマクロ名
72
-
62
+
73
-   End With
63
+ End With
74
64
 
75
65
 
76
66
 
77
67
  Set cmdBra2 = cmdBra1.Controls.Add()
78
68
 
79
-   With cmdBra2
69
+ With cmdBra2
80
-
70
+
81
-   .Caption = **"キャベツ"**
71
+ .Caption = "白菜"
82
-
72
+
83
-   .FaceId = 2
73
+ .FaceId = 2
84
-
74
+
85
-   .OnAction = **"キャベツ"**
75
+ .OnAction = "白菜"
86
-
76
+
87
-  End With
77
+ End With
88
-
89
- **End If**     **> A列が選択されたら野菜項目を表示終了 通常メニューも表示したい**
78
+
90
-
91
-
92
-
93
- If Not Application.Intersect(Target, Range("__B:B__")) Is Nothing Then
79
+
94
-
80
+
95
- Set cmdBra3 = Application.CommandBars("__Cell__").Controls.Add(Before:=1, Type:=msoControlPopup)
81
+ Set cmdBra2 = cmdBra1.Controls.Add()
96
-
82
+
97
-   ##### With cmdBra3
83
+ With cmdBra2
98
-
84
+
99
-    .Caption = **"▽果物▽**"      **> B列に大分類「果物」を表示。その中に苺等小分類を入れてます**
85
+ .Caption = "キャベツ"
86
+
100
-
87
+ .FaceId = 2
88
+
89
+ .OnAction = "キャベツ"
90
+
101
-   End With
91
+ End With
92
+
102
-
93
+ End If
94
+
95
+
96
+
103
-
97
+ If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
104
-
98
+
99
+
100
+
105
- Set cmdBra4 = cmdBra3.Controls.Add()
101
+ Set cmdBra3 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
106
-
102
+
107
-   With cmdBra4
103
+ With cmdBra3
108
-
104
+
109
-    .Caption = **""**
105
+ .Caption = "▽果物▽"
110
-
111
-    .FaceId = 2
106
+
112
-
113
-    .OnAction = **"苺"**
114
-
115
-   End With
107
+ End With
116
108
 
117
109
 
118
110
 
119
111
  Set cmdBra4 = cmdBra3.Controls.Add()
120
112
 
121
-   With cmdBra4
113
+ With cmdBra4
122
-
114
+
123
-    .Caption = "**リンゴ**"
115
+ .Caption = ""
124
-
116
+
125
-    .FaceId = 2
117
+ .FaceId = 2
126
-
118
+
127
-    .OnAction = "**リンゴ**"
119
+ .OnAction = ""
128
-
120
+
129
-   End With
121
+ End With
130
-
131
-
132
122
 
133
123
  Set cmdBra4 = cmdBra3.Controls.Add()
134
124
 
135
-   With cmdBra4
125
+ With cmdBra4
136
-
126
+
137
-    .Caption = "**バナナ**"
127
+ .Caption = "リンゴ"
138
-
128
+
139
-    .FaceId = 2
129
+ .FaceId = 2
140
-
130
+
141
-    .OnAction = "**バナナ**"
131
+ .OnAction = "リンゴ"
142
-
132
+
143
-   End With
133
+ End With
144
-
145
-  **End If**     **> B列が選択されたら野菜項目を表示終了 通常メニューも表示したい**
134
+
146
-
147
-
148
-
149
- If Not Application.Intersect(Target, Range("__C:C__")) Is Nothing Then
150
-
151
- Set cmdBra5 = Application.CommandBars("__Cell__").Controls.Add(Before:=1, Type:=msoControlPopup)
135
+ Set cmdBra4 = cmdBra3.Controls.Add()
152
-
136
+
153
-   ##### With cmdBra5
137
+ With cmdBra4
154
-
138
+
155
-    .Caption = **"▽精肉▽"** **> C列に大分類「精肉」を表示。その中に豚肉等小分類を入れてます**
139
+ .Caption = "バナナ"
140
+
156
-
141
+ .FaceId = 2
142
+
143
+ .OnAction = "バナナ"
144
+
157
-   End With
145
+ End With
146
+
158
-
147
+ End If
148
+
159
-
149
+ If Not Application.Intersect(Target, Range("C:C")) Is Nothing Then
150
+
151
+ Set cmdBra5 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
152
+
153
+ With cmdBra5
154
+
155
+ .Caption = "▽精肉▽"
156
+
157
+ End With
160
158
 
161
159
  Set cmdBra6 = cmdBra5.Controls.Add()
162
160
 
163
-   With cmdBra6
161
+ With cmdBra6
164
-
162
+
165
-    .Caption = **"豚肉"**
163
+ .Caption = "豚肉"
166
-
164
+
167
-    .FaceId = 2
165
+ .FaceId = 2
168
-
166
+
169
-    .OnAction = **"豚肉"**
167
+ .OnAction = "豚肉"
170
-
168
+
171
-   End With
169
+ End With
172
-
173
-
174
170
 
175
171
  Set cmdBra6 = cmdBra5.Controls.Add()
176
172
 
177
-   With cmdBra6
173
+ With cmdBra6
178
-
174
+
179
-    .Caption = **"牛肉"**
175
+ .Caption = "牛肉"
180
-
176
+
181
-    .FaceId = 2
177
+ .FaceId = 2
182
-
178
+
183
-    .OnAction = **"牛肉"**
179
+ .OnAction = "牛肉"
184
-
180
+
185
-   End With
181
+ End With
186
-
187
-
188
182
 
189
183
  Set cmdBra6 = cmdBra5.Controls.Add()
190
184
 
191
-   With cmdBra6
185
+ With cmdBra6
192
-
186
+
193
-    .Caption = **"鶏肉"**
187
+ .Caption = "鶏肉"
194
-
188
+
195
-    .FaceId = 2
189
+ .FaceId = 2
196
-
190
+
197
-    .OnAction = **"鶏肉"**
191
+ .OnAction = "鶏肉"
198
-
192
+
199
-   End With
193
+ End With
200
-
201
-
202
-
194
+
195
+
196
+
203
- Set cmdBra7 = Application.CommandBars("__Cell__").Controls.Add(Before:=2, Type:=msoControlPopup)
197
+ Set cmdBra7 = Application.CommandBars("Cell").Controls.Add(Before:=2, Type:=msoControlPopup)
204
-
198
+
205
-   ##### With cmdBra7
199
+ With cmdBra7
206
-
200
+
207
-    .Caption = **"▼鮮魚▼"**
201
+ .Caption = "▼鮮魚▼"
208
-
202
+
209
-   End With
203
+ End With
210
-
211
-
212
204
 
213
205
  Set cmdBra8 = cmdBra7.Controls.Add()
214
206
 
215
-   With cmdBra8
207
+ With cmdBra8
216
-
208
+
217
-    .Caption = **"鮭"**
209
+ .Caption = "鮭"
218
-
210
+
219
-    .FaceId = 2
211
+ .FaceId = 2
220
-
212
+
221
-    .OnAction = **"鮭"**
213
+ .OnAction = "鮭"
222
-
214
+
223
-   End With
215
+ End With
224
-
225
-
226
216
 
227
217
  Set cmdBra8 = cmdBra7.Controls.Add()
228
218
 
229
-   With cmdBra8
219
+ With cmdBra8
230
-
220
+
231
-    .Caption = **"鯖"**
221
+ .Caption = "鯖"
232
-
222
+
233
-    .FaceId = 2
223
+ .FaceId = 2
234
-
224
+
235
-    .OnAction = **"鯖"**
225
+ .OnAction = "鯖"
236
-
226
+
237
-   End With
227
+ End With
238
-
239
-
240
-
228
+
241
- Set cmdBra8 = cmdBra7.Controls.Add()
229
+ Set cmdBra8 = cmdBra7.Controls.Add()
242
-
230
+
243
-   With cmdBra8
231
+ With cmdBra8
244
-
232
+
245
-    .Caption = **"秋刀魚"**
233
+ .Caption = "秋刀魚"
246
-
234
+
247
-    .FaceId = 2
235
+ .FaceId = 2
248
-
236
+
249
-    .OnAction = **"秋刀魚"**
237
+ .OnAction = "秋刀魚"
250
-
238
+
251
-   End With
239
+ End With
252
-
240
+
253
-  ##### End If           **> C列が選択されたら精肉・鮮魚項目を表示終了 通常メニューも表示したい**
241
+ End If
254
-
255
-
256
-
257
-
258
-
242
+
259
- Application.CommandBars("__Cell__").ShowPopup
243
+ Application.CommandBars("Cell").ShowPopup
260
-
244
+
261
- Application.CommandBars("__Cell__").Reset
245
+ Application.CommandBars("Cell").Reset
262
246
 
263
247
  Cancel = True
264
248
 
265
- End Sub`````````
249
+ End Sub```
250
+
251
+
252
+
253
+
254
+
266
-
255
+ ``````
267
-
268
-
269
-
270
256
 
271
257
  ```別VBA
272
258
 

4

太字にしました

2019/06/07 07:20

投稿

saku88
saku88

スコア11

test CHANGED
File without changes
test CHANGED
@@ -16,224 +16,268 @@
16
16
 
17
17
 
18
18
 
19
- ```VBA Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl,cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl, cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl, cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
19
+ ```VBA
20
+
21
+ Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl
22
+
23
+ Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
24
+
25
+ Dim cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl
26
+
27
+ Dim cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
28
+
29
+
30
+
31
+ Private Sub Worksheet_BeforeRightClick(**ByVal** Target As Range, Cancel As **Boolean**)
32
+
33
+
34
+
35
+ If Not Application.Intersect(Target, Range("__A:A__")) Is Nothing Then
36
+
37
+ '以下で、新規のメニューを追加
38
+
39
+ Set cmdBra1 = Application.CommandBars("__Cell__").Controls.Add(Before:=1, Type:=msoControlPopup)
40
+
41
+  ###### With cmdBra1
42
+
43
+   .Caption = **"▽野菜▽" **'グループメニュー名    **> A列に大分類「野菜を表示」その中に胡瓜等小分類を入れてます**
44
+
45
+   End With
46
+
47
+
48
+
49
+ Set cmdBra2 = cmdBra1.Controls.Add()
50
+
51
+   With cmdBra2
52
+
53
+    .Caption = **"胡瓜"** 'メニュー表示名
54
+
55
+    .FaceId = 2
56
+
57
+    .OnAction = **"胡瓜"** '実行するマクロ名
58
+
59
+   End With
60
+
61
+
62
+
63
+ Set cmdBra2 = cmdBra1.Controls.Add()
64
+
65
+   With cmdBra2
66
+
67
+    .Caption = **"白菜"**
68
+
69
+    .FaceId = 2
70
+
71
+    .OnAction = **"白菜"**
72
+
73
+   End With
74
+
75
+
76
+
77
+ Set cmdBra2 = cmdBra1.Controls.Add()
78
+
79
+   With cmdBra2
80
+
81
+   .Caption = **"キャベツ"**
82
+
83
+   .FaceId = 2
84
+
85
+   .OnAction = **"キャベツ"**
86
+
87
+  End With
88
+
89
+ **End If**     **> A列が選択されたら野菜項目を表示終了 通常メニューも表示したい**
90
+
91
+
92
+
93
+ If Not Application.Intersect(Target, Range("__B:B__")) Is Nothing Then
94
+
95
+ Set cmdBra3 = Application.CommandBars("__Cell__").Controls.Add(Before:=1, Type:=msoControlPopup)
96
+
97
+   ##### With cmdBra3
98
+
99
+    .Caption = **"▽果物▽**"      **> B列に大分類「果物」を表示。その中に苺等小分類を入れてます**
100
+
101
+   End With
102
+
103
+
104
+
105
+ Set cmdBra4 = cmdBra3.Controls.Add()
106
+
107
+   With cmdBra4
108
+
109
+    .Caption = **"苺"**
110
+
111
+    .FaceId = 2
112
+
113
+    .OnAction = **"苺"**
114
+
115
+   End With
116
+
117
+
118
+
119
+ Set cmdBra4 = cmdBra3.Controls.Add()
120
+
121
+   With cmdBra4
122
+
123
+    .Caption = "**リンゴ**"
124
+
125
+    .FaceId = 2
126
+
127
+    .OnAction = "**リンゴ**"
128
+
129
+   End With
130
+
131
+
132
+
133
+ Set cmdBra4 = cmdBra3.Controls.Add()
134
+
135
+   With cmdBra4
136
+
137
+    .Caption = "**バナナ**"
138
+
139
+    .FaceId = 2
140
+
141
+    .OnAction = "**バナナ**"
142
+
143
+   End With
144
+
145
+  **End If**     **> B列が選択されたら野菜項目を表示終了 通常メニューも表示したい**
146
+
147
+
148
+
149
+ If Not Application.Intersect(Target, Range("__C:C__")) Is Nothing Then
150
+
151
+ Set cmdBra5 = Application.CommandBars("__Cell__").Controls.Add(Before:=1, Type:=msoControlPopup)
152
+
153
+   ##### With cmdBra5
154
+
155
+    .Caption = **"▽精肉▽"** **> C列に大分類「精肉」を表示。その中に豚肉等小分類を入れてます**
156
+
157
+   End With
158
+
159
+
160
+
161
+ Set cmdBra6 = cmdBra5.Controls.Add()
162
+
163
+   With cmdBra6
164
+
165
+    .Caption = **"豚肉"**
166
+
167
+    .FaceId = 2
168
+
169
+    .OnAction = **"豚肉"**
170
+
171
+   End With
172
+
173
+
174
+
175
+ Set cmdBra6 = cmdBra5.Controls.Add()
176
+
177
+   With cmdBra6
178
+
179
+    .Caption = **"牛肉"**
180
+
181
+    .FaceId = 2
182
+
183
+    .OnAction = **"牛肉"**
184
+
185
+   End With
186
+
187
+
188
+
189
+ Set cmdBra6 = cmdBra5.Controls.Add()
190
+
191
+   With cmdBra6
192
+
193
+    .Caption = **"鶏肉"**
194
+
195
+    .FaceId = 2
196
+
197
+    .OnAction = **"鶏肉"**
198
+
199
+   End With
200
+
201
+
202
+
203
+ Set cmdBra7 = Application.CommandBars("__Cell__").Controls.Add(Before:=2, Type:=msoControlPopup)
204
+
205
+   ##### With cmdBra7
206
+
207
+    .Caption = **"▼鮮魚▼"**
208
+
209
+   End With
210
+
211
+
212
+
213
+ Set cmdBra8 = cmdBra7.Controls.Add()
214
+
215
+   With cmdBra8
216
+
217
+    .Caption = **"鮭"**
218
+
219
+    .FaceId = 2
220
+
221
+    .OnAction = **"鮭"**
222
+
223
+   End With
224
+
225
+
226
+
227
+ Set cmdBra8 = cmdBra7.Controls.Add()
228
+
229
+   With cmdBra8
230
+
231
+    .Caption = **"鯖"**
232
+
233
+    .FaceId = 2
234
+
235
+    .OnAction = **"鯖"**
236
+
237
+   End With
238
+
239
+
240
+
241
+ Set cmdBra8 = cmdBra7.Controls.Add()
242
+
243
+   With cmdBra8
244
+
245
+    .Caption = **"秋刀魚"**
246
+
247
+    .FaceId = 2
248
+
249
+    .OnAction = **"秋刀魚"**
250
+
251
+   End With
252
+
253
+  ##### End If           **> C列が選択されたら精肉・鮮魚項目を表示終了 通常メニューも表示したい**
254
+
255
+
256
+
257
+
258
+
259
+ Application.CommandBars("__Cell__").ShowPopup
260
+
261
+ Application.CommandBars("__Cell__").Reset
262
+
263
+ Cancel = True
264
+
265
+ End Sub`````````
266
+
267
+
268
+
269
+
270
+
271
+ ```別VBA
272
+
273
+ Dim cmdBar As CommandBar, cmdBarc1 As CommandBarControl
274
+
275
+ Dim cmdBarc2 As CommandBarControl
276
+
277
+
20
278
 
21
279
  Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
22
280
 
23
-   If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then
24
-
25
-   '以下で、新規のメニューを追加
26
-
27
-  Set cmdBra1 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
28
-
29
-   With cmdBra1
30
-
31
-    .Caption = "▽野菜▽" 'グループメニュー名
32
-
33
-   End With
34
-
35
- Set cmdBra2 = cmdBra1.Controls.Add()
36
-
37
-   With cmdBra2
38
-
39
-    .Caption = "胡瓜" 'メニュー表示名
40
-
41
-    .FaceId = 2
42
-
43
-    .OnAction = "胡瓜" '実行するマクロ名
44
-
45
-   End With
46
-
47
- Set cmdBra2 = cmdBra1.Controls.Add()
48
-
49
-   With cmdBra2
50
-
51
-    .Caption = "白菜"
52
-
53
-    .FaceId = 2
54
-
55
-    .OnAction = "白菜"
56
-
57
-   End With
58
-
59
- Set cmdBra2 = cmdBra1.Controls.Add()
60
-
61
-   With cmdBra2
62
-
63
-   .Caption = "キャベツ"
64
-
65
-   .FaceId = 2
66
-
67
-   .OnAction = "キャベツ"
68
-
69
-  End With
70
-
71
-  End If
72
-
73
- If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
74
-
75
- Set cmdBra3 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
76
-
77
-   With cmdBra3
78
-
79
-    .Caption = "▽果物▽"
80
-
81
-   End With
82
-
83
- Set cmdBra4 = cmdBra3.Controls.Add()
84
-
85
-   With cmdBra4
86
-
87
-    .Caption = "苺"
88
-
89
-    .FaceId = 2
90
-
91
-    .OnAction = "苺"
92
-
93
-   End With
94
-
95
- Set cmdBra4 = cmdBra3.Controls.Add()
96
-
97
-   With cmdBra4
98
-
99
-    .Caption = "リンゴ"
100
-
101
-    .FaceId = 2
102
-
103
-    .OnAction = "リンゴ"
104
-
105
-   End With
106
-
107
- Set cmdBra4 = cmdBra3.Controls.Add()
108
-
109
-   With cmdBra4
110
-
111
-    .Caption = "バナナ"
112
-
113
-    .FaceId = 2
114
-
115
-    .OnAction = "バナナ"
116
-
117
-   End With
118
-
119
-  End If
120
-
121
- If Not Application.Intersect(Target, Range("C:C")) Is Nothing Then
122
-
123
- Set cmdBra5 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
124
-
125
-   With cmdBra5
126
-
127
-    .Caption = "▽精肉▽"
128
-
129
-   End With
130
-
131
- Set cmdBra6 = cmdBra5.Controls.Add()
132
-
133
-   With cmdBra6
134
-
135
-    .Caption = "豚肉"
136
-
137
-    .FaceId = 2
138
-
139
-    .OnAction = "豚肉"
140
-
141
-   End With
142
-
143
- Set cmdBra6 = cmdBra5.Controls.Add()
144
-
145
-   With cmdBra6
146
-
147
-    .Caption = "牛肉"
148
-
149
-    .FaceId = 2
150
-
151
-    .OnAction = "牛肉"
152
-
153
-   End With
154
-
155
- Set cmdBra6 = cmdBra5.Controls.Add()
156
-
157
-   With cmdBra6
158
-
159
-    .Caption = "鶏肉"
160
-
161
-    .FaceId = 2
162
-
163
-    .OnAction = "鶏肉"
164
-
165
-   End With
166
-
167
-
168
-
169
- Set cmdBra7 = Application.CommandBars("Cell").Controls.Add(Before:=2, Type:=msoControlPopup)
170
-
171
-   With cmdBra7
172
-
173
-    .Caption = "▼鮮魚▼"
174
-
175
-   End With
176
-
177
- Set cmdBra8 = cmdBra7.Controls.Add()
178
-
179
-   With cmdBra8
180
-
181
-    .Caption = "鮭"
182
-
183
-    .FaceId = 2
184
-
185
-    .OnAction = "鮭"
186
-
187
-   End With
188
-
189
- Set cmdBra8 = cmdBra7.Controls.Add()
190
-
191
-   With cmdBra8
192
-
193
-    .Caption = "鯖"
194
-
195
-    .FaceId = 2
196
-
197
-    .OnAction = "鯖"
198
-
199
-   End With
200
-
201
- Set cmdBra8 = cmdBra7.Controls.Add()
202
-
203
-   With cmdBra8
204
-
205
-    .Caption = "秋刀魚"
206
-
207
-    .FaceId = 2
208
-
209
-    .OnAction = "秋刀魚"
210
-
211
-   End With
212
-
213
-   End If
214
-
215
-
216
-
217
- Application.CommandBars("Cell").ShowPopup
218
-
219
- Application.CommandBars("Cell").Reset
220
-
221
- Cancel = True
222
-
223
- End Sub`````````
224
-
225
-
226
-
227
- ```別VBA
228
-
229
- Dim cmdBar As CommandBar, cmdBarc1 As CommandBarControl
230
-
231
- Dim cmdBarc2 As CommandBarControl
232
-
233
-
234
-
235
- Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
236
-
237
281
  If Not Application.Intersect(Target, Range("I:I")) Is Nothing Then
238
282
 
239
283
  Set cmdBar = Application.CommandBars("Cell")

3

修正しました!

2019/06/07 06:29

投稿

saku88
saku88

スコア11

test CHANGED
File without changes
test CHANGED
@@ -16,19 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- VBA
20
-
21
- ```ここに言語を入力
22
-
23
- Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl
24
-
25
- Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
26
-
27
- Dim cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl
28
-
29
- Dim cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
30
-
31
-
19
+ ```VBA Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl,cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl, cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl, cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
32
20
 
33
21
  Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
34
22
 
@@ -82,8 +70,6 @@
82
70
 
83
71
   End If
84
72
 
85
-
86
-
87
73
  If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
88
74
 
89
75
  Set cmdBra3 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
@@ -132,8 +118,6 @@
132
118
 
133
119
   End If
134
120
 
135
-
136
-
137
121
  If Not Application.Intersect(Target, Range("C:C")) Is Nothing Then
138
122
 
139
123
  Set cmdBra5 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
@@ -236,70 +220,56 @@
236
220
 
237
221
  Cancel = True
238
222
 
223
+ End Sub`````````
224
+
225
+
226
+
227
+ ```別VBA
228
+
229
+ Dim cmdBar As CommandBar, cmdBarc1 As CommandBarControl
230
+
231
+ Dim cmdBarc2 As CommandBarControl
232
+
233
+
234
+
235
+ Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
236
+
237
+ If Not Application.Intersect(Target, Range("I:I")) Is Nothing Then
238
+
239
+ Set cmdBar = Application.CommandBars("Cell")
240
+
241
+ Set cmdBarc1 = cmdBar.Controls.Add(Before:=1, Type:=msoControlPopup)
242
+
243
+ With cmdBarc1
244
+
245
+ .Caption = "▽野菜▽"
246
+
247
+ With .Controls.Add
248
+
249
+ .Caption = "胡瓜"
250
+
251
+ .OnAction = "胡瓜"
252
+
239
- End Sub
253
+ End With
254
+
255
+ With .Controls.Add
256
+
257
+ .Caption = "白菜"
258
+
259
+ .OnAction = "白菜"
260
+
261
+ End With
262
+
263
+ End IF・・・以下同文``````
264
+
265
+
266
+
267
+ 上記のVBAだとEnd Ifが不要とのエラーになり、最初の「野菜」メニューしか表示されません
240
268
 
241
269
 
242
270
 
243
271
  ``````
244
272
 
245
-
246
-
247
- 別VBA
248
-
249
- ```ここに言語を入力
250
-
251
- Dim cmdBar As CommandBar, cmdBarc1 As CommandBarControl
252
-
253
- Dim cmdBarc2 As CommandBarControl
254
-
255
-
256
-
257
- Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
258
-
259
- If Not Application.Intersect(Target, Range("I:I")) Is Nothing Then
260
-
261
- Set cmdBar = Application.CommandBars("Cell")
262
-
263
- Set cmdBarc1 = cmdBar.Controls.Add(Before:=1, Type:=msoControlPopup)
264
-
265
- With cmdBarc1
266
-
267
- .Caption = "▽野菜▽"
268
-
269
- With .Controls.Add
270
-
271
- .Caption = "胡瓜"
272
-
273
- .OnAction = "胡瓜"
274
-
275
- End With
276
-
277
- With .Controls.Add
278
-
279
- .Caption = "白菜"
280
-
281
- .OnAction = "白菜"
282
-
283
- End With
284
-
285
- End IF・・・以下同文
286
-
287
-
288
-
289
-
290
-
291
- ``````
292
-
293
- 上記のVBAだとEnd Ifが不要とのエラーになり、最初の「野菜」メニューしか表示されません
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
- ``````
302
-
303
273
  ### 試したこと
304
274
 
305
275
 

2

コード部分に入れてみました

2019/06/07 04:05

投稿

saku88
saku88

スコア11

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- ### 前提・実現したいこと
1
+ ```### 前提・実現したいこと
2
2
 
3
3
 
4
4
 
@@ -18,213 +18,217 @@
18
18
 
19
19
  VBA
20
20
 
21
- ``````ここに言語を入力
21
+ ```ここに言語を入力
22
-
23
- ここに言語を入力
24
-
25
- ```
26
22
 
27
23
  Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl
28
24
 
29
- Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
25
+ Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
30
-
26
+
31
- Dim cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl
27
+ Dim cmdBra5 As CommandBarControl, cmdBra6 As CommandBarControl
32
-
28
+
33
- Dim cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
29
+ Dim cmdBra7 As CommandBarControl, cmdBra8 As CommandBarControl
30
+
31
+
34
32
 
35
33
  Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
36
34
 
37
- If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then
35
+   If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then
38
-
36
+
39
- '以下で、新規のメニューを追加
37
+   '以下で、新規のメニューを追加
40
-
38
+
41
- Set cmdBra1 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
39
+  Set cmdBra1 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
42
-
40
+
43
- With cmdBra1
41
+   With cmdBra1
44
-
42
+
45
- .Caption = "▽野菜▽" 'グループメニュー名
43
+    .Caption = "▽野菜▽" 'グループメニュー名
46
-
44
+
47
- End With
45
+   End With
48
46
 
49
47
  Set cmdBra2 = cmdBra1.Controls.Add()
50
48
 
51
- With cmdBra2
49
+   With cmdBra2
52
-
50
+
53
- .Caption = "胡瓜" 'メニュー表示名
51
+    .Caption = "胡瓜" 'メニュー表示名
54
-
52
+
55
- .FaceId = 2
53
+    .FaceId = 2
56
-
54
+
57
- .OnAction = "胡瓜" '実行するマクロ名
55
+    .OnAction = "胡瓜" '実行するマクロ名
58
-
56
+
59
- End With
57
+   End With
60
58
 
61
59
  Set cmdBra2 = cmdBra1.Controls.Add()
62
60
 
63
- With cmdBra2
61
+   With cmdBra2
64
-
62
+
65
- .Caption = "白菜"
63
+    .Caption = "白菜"
66
-
64
+
67
- .FaceId = 2
65
+    .FaceId = 2
68
-
66
+
69
- .OnAction = "白菜"
67
+    .OnAction = "白菜"
70
-
68
+
71
- End With
69
+   End With
72
70
 
73
71
  Set cmdBra2 = cmdBra1.Controls.Add()
74
72
 
75
- With cmdBra2
73
+   With cmdBra2
76
-
74
+
77
- .Caption = "キャベツ"
75
+   .Caption = "キャベツ"
78
-
76
+
79
- .FaceId = 2
77
+   .FaceId = 2
80
-
78
+
81
- .OnAction = "キャベツ"
79
+   .OnAction = "キャベツ"
82
-
80
+
83
- End With
81
+  End With
84
-
82
+
85
- End If
83
+  End If
86
-
84
+
85
+
86
+
87
- If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
87
+ If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
88
88
 
89
89
  Set cmdBra3 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
90
90
 
91
- With cmdBra3
91
+   With cmdBra3
92
-
92
+
93
- .Caption = "▽果物▽"
93
+    .Caption = "▽果物▽"
94
-
94
+
95
- End With
95
+   End With
96
96
 
97
97
  Set cmdBra4 = cmdBra3.Controls.Add()
98
98
 
99
- With cmdBra4
99
+   With cmdBra4
100
-
100
+
101
- .Caption = "苺"
101
+    .Caption = "苺"
102
-
102
+
103
- .FaceId = 2
103
+    .FaceId = 2
104
-
104
+
105
- .OnAction = "苺"
105
+    .OnAction = "苺"
106
-
106
+
107
- End With
107
+   End With
108
108
 
109
109
  Set cmdBra4 = cmdBra3.Controls.Add()
110
110
 
111
- With cmdBra4
111
+   With cmdBra4
112
-
112
+
113
- .Caption = "リンゴ"
113
+    .Caption = "リンゴ"
114
-
114
+
115
- .FaceId = 2
115
+    .FaceId = 2
116
-
116
+
117
- .OnAction = "リンゴ"
117
+    .OnAction = "リンゴ"
118
-
118
+
119
- End With
119
+   End With
120
120
 
121
121
  Set cmdBra4 = cmdBra3.Controls.Add()
122
122
 
123
- With cmdBra4
123
+   With cmdBra4
124
-
124
+
125
- .Caption = "バナナ"
125
+    .Caption = "バナナ"
126
-
126
+
127
- .FaceId = 2
127
+    .FaceId = 2
128
-
128
+
129
- .OnAction = "バナナ"
129
+    .OnAction = "バナナ"
130
-
130
+
131
- End With
131
+   End With
132
-
132
+
133
- End If
133
+  End If
134
+
135
+
134
136
 
135
137
  If Not Application.Intersect(Target, Range("C:C")) Is Nothing Then
136
138
 
137
139
  Set cmdBra5 = Application.CommandBars("Cell").Controls.Add(Before:=1, Type:=msoControlPopup)
138
140
 
139
- With cmdBra5
141
+   With cmdBra5
140
-
142
+
141
- .Caption = "▽精肉▽"
143
+    .Caption = "▽精肉▽"
142
-
144
+
143
- End With
145
+   End With
144
146
 
145
147
  Set cmdBra6 = cmdBra5.Controls.Add()
146
148
 
147
- With cmdBra6
149
+   With cmdBra6
148
-
150
+
149
- .Caption = "豚肉"
151
+    .Caption = "豚肉"
150
-
152
+
151
- .FaceId = 2
153
+    .FaceId = 2
152
-
154
+
153
- .OnAction = "豚肉"
155
+    .OnAction = "豚肉"
154
-
156
+
155
- End With
157
+   End With
156
158
 
157
159
  Set cmdBra6 = cmdBra5.Controls.Add()
158
160
 
159
- With cmdBra6
161
+   With cmdBra6
160
-
162
+
161
- .Caption = "牛肉"
163
+    .Caption = "牛肉"
162
-
164
+
163
- .FaceId = 2
165
+    .FaceId = 2
164
-
166
+
165
- .OnAction = "牛肉"
167
+    .OnAction = "牛肉"
166
-
168
+
167
- End With
169
+   End With
168
170
 
169
171
  Set cmdBra6 = cmdBra5.Controls.Add()
170
172
 
171
- With cmdBra6
173
+   With cmdBra6
172
-
174
+
173
- .Caption = "鶏肉"
175
+    .Caption = "鶏肉"
174
-
176
+
175
- .FaceId = 2
177
+    .FaceId = 2
176
-
178
+
177
- .OnAction = "鶏肉"
179
+    .OnAction = "鶏肉"
178
-
180
+
179
- End With
181
+   End With
180
182
 
181
183
 
182
184
 
183
185
  Set cmdBra7 = Application.CommandBars("Cell").Controls.Add(Before:=2, Type:=msoControlPopup)
184
186
 
185
- With cmdBra7
187
+   With cmdBra7
186
-
188
+
187
- .Caption = "▼鮮魚▼"
189
+    .Caption = "▼鮮魚▼"
188
-
190
+
189
- End With
191
+   End With
190
192
 
191
193
  Set cmdBra8 = cmdBra7.Controls.Add()
192
194
 
193
- With cmdBra8
195
+   With cmdBra8
194
-
196
+
195
- .Caption = "鮭"
197
+    .Caption = "鮭"
196
-
198
+
197
- .FaceId = 2
199
+    .FaceId = 2
198
-
200
+
199
- .OnAction = "鮭"
201
+    .OnAction = "鮭"
200
-
202
+
201
- End With
203
+   End With
202
204
 
203
205
  Set cmdBra8 = cmdBra7.Controls.Add()
204
206
 
205
- With cmdBra8
207
+   With cmdBra8
206
-
208
+
207
- .Caption = "鯖"
209
+    .Caption = "鯖"
208
-
210
+
209
- .FaceId = 2
211
+    .FaceId = 2
210
-
212
+
211
- .OnAction = "鯖"
213
+    .OnAction = "鯖"
212
-
214
+
213
- End With
215
+   End With
214
216
 
215
217
  Set cmdBra8 = cmdBra7.Controls.Add()
216
218
 
217
- With cmdBra8
219
+   With cmdBra8
218
-
220
+
219
- .Caption = "秋刀魚"
221
+    .Caption = "秋刀魚"
220
-
222
+
221
- .FaceId = 2
223
+    .FaceId = 2
222
-
224
+
223
- .OnAction = "秋刀魚"
225
+    .OnAction = "秋刀魚"
224
-
226
+
225
- End With
227
+   End With
226
-
228
+
227
- End If
229
+   End If
230
+
231
+
228
232
 
229
233
  Application.CommandBars("Cell").ShowPopup
230
234
 
@@ -236,7 +240,65 @@
236
240
 
237
241
 
238
242
 
239
- ```
243
+ ``````
244
+
245
+
246
+
247
+ 別VBA
248
+
249
+ ```ここに言語を入力
250
+
251
+ Dim cmdBar As CommandBar, cmdBarc1 As CommandBarControl
252
+
253
+ Dim cmdBarc2 As CommandBarControl
254
+
255
+
256
+
257
+ Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
258
+
259
+ If Not Application.Intersect(Target, Range("I:I")) Is Nothing Then
260
+
261
+ Set cmdBar = Application.CommandBars("Cell")
262
+
263
+ Set cmdBarc1 = cmdBar.Controls.Add(Before:=1, Type:=msoControlPopup)
264
+
265
+ With cmdBarc1
266
+
267
+ .Caption = "▽野菜▽"
268
+
269
+ With .Controls.Add
270
+
271
+ .Caption = "胡瓜"
272
+
273
+ .OnAction = "胡瓜"
274
+
275
+ End With
276
+
277
+ With .Controls.Add
278
+
279
+ .Caption = "白菜"
280
+
281
+ .OnAction = "白菜"
282
+
283
+ End With
284
+
285
+ End IF・・・以下同文
286
+
287
+
288
+
289
+
290
+
291
+ ``````
292
+
293
+ 上記のVBAだとEnd Ifが不要とのエラーになり、最初の「野菜」メニューしか表示されません
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+ ``````
240
302
 
241
303
  ### 試したこと
242
304
 
@@ -252,48 +314,6 @@
252
314
 
253
315
 
254
316
 
255
- 別ソース
256
-
257
- 別VBA(抜粋)
258
-
259
- Dim cmdBar As CommandBar, cmdBarc1 As CommandBarControl
260
-
261
- Dim cmdBarc2 As CommandBarControl
262
-
263
- Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
264
-
265
-
266
-
267
- If Not Application.Intersect(Target, Range("I:I")) Is Nothing Then
268
-
269
- Set cmdBar = Application.CommandBars("Cell")
270
-
271
- Set cmdBarc1 = cmdBar.Controls.Add(Before:=1, Type:=msoControlPopup)
272
-
273
- With cmdBarc1
274
-
275
- .Caption = "▽野菜▽"
276
-
277
- With .Controls.Add
278
-
279
- .Caption = "胡瓜"
280
-
281
- .OnAction = "胡瓜"
282
-
283
- End With
284
-
285
- With .Controls.Add
286
-
287
- .Caption = "白菜"
288
-
289
- .OnAction = "白菜"
290
-
291
- End With
292
-
293
- End IF・・・以下同文
294
-
295
- 上記のVBAだとEnd Ifが不要とのエラーになり、最初の「野菜」メニューしか表示されません
296
-
297
317
 
298
318
 
299
319
 

1

やり方が分かっていず、申し訳ありません。<code>ボタンをクリックしました。ご指摘有難うございます。

2019/06/07 02:54

投稿

saku88
saku88

スコア11

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,12 @@
18
18
 
19
19
  VBA
20
20
 
21
+ ``````ここに言語を入力
22
+
23
+ ここに言語を入力
24
+
25
+ ```
26
+
21
27
  Dim cmdBra1 As CommandBarControl, cmdBra2 As CommandBarControl
22
28
 
23
29
  Dim cmdBra3 As CommandBarControl, cmdBra4 As CommandBarControl
@@ -230,6 +236,8 @@
230
236
 
231
237
 
232
238
 
239
+ ```
240
+
233
241
  ### 試したこと
234
242
 
235
243