
Sub 自作コマンドバー()
Dim cb As CommandBar
Dim cb1 As CommandBarButton
On Error Resume Next
CommandBars("mycb").Delete
On Error GoTo 0
Set cb = Application.CommandBars.Add(Name:="mycb", Temporary:=True)
With cb
.Controls.Add Type:=msoControlButton, ID:=23, before:=1
.Controls.Add Type:=msoControlButton, ID:=3, before:=2
.Visible = True
.Position = msoBarTop
End With
Set cb1 = cb.Controls.Add(Type:=msoControlButton, before:=3)
With cb1
.BeginGroup = True
.Caption = "画像の取り込み"
.FaceId = 931
.OnAction = "Macro1"
End With
Set cb1 = cb.Controls.Add(Type:=msoControlButton, before:=4)
With cb1
.Caption = "画像の切り取り"
.FaceId = 21
.OnAction = "Macro1"
End With
End Sub
|



Sub ショートメニュー1()
With CommandBars("cell").Controls.Add(Temporary:=True)
.Caption = "Webから株価ロード"
.OnAction = "Macro1"
.BeginGroup = True
End With
End Sub
--------------------------------------------------------
Sub ショートメニュー2()
Dim cb As CommandBarButton
Set cb = Application.CommandBars("cell").Controls.Add _
(Type:=msoControlButton, Before:=7, temporary:=True)
With cb
.Caption = "Webから株価ロード"
.OnAction = "Macro1"
End With
End Sub
--------------------------------------------------------
Sub ショートメニュー3()
ShortcutMenus(xlWorksheetCell).MenuItems.Add "-"
ShortcutMenus(xlWorksheetCell).MenuItems.Add "Webから株価ロード", "Macro1"
End Sub
上記のAdd "-"で区切り線が入ります
--------------------------------------------------------
Sub ショートメニュー削除()
On Error Resume Next
CommandBars("cell").Controls("Webから株価ロード").Delete
On Error GoTo 0
End Sub
|
「Sheet1」コードウインドウ |
| Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Cancel = True MsgBox "ショートカットメニュー「キャンセル」になっています" End Sub |


Sub 既存アイテムへ追加()
Dim menu As CommandBar
Set menu = Application.CommandBars("Worksheet Menu Bar")
Set menu1 = menu.Controls("ツール(&T)")
Set menu2 = menu1.Controls.Add(Type:=msoControlButton, Temporary:=True)
With menu2
.Caption = "Webからロード"
.OnAction = "Macro1"
End With
End Sub
----------------------------------------------------------
Sub 既存アイテムへ削除()
CommandBars("worksheet menu bar").Reset
End Sub
|


Sub メニューへ新規追加()
Set menu1 = Application.CommandBars("worksheet menu bar")
Set menu2 = menu1.Controls.Add(Type:=msoControlPopup, Temporary:=True)
menu2.Caption = "追加メニュー"
With menu2
.Controls.Add Type:=msoControlButton
With .Controls(1)
.Caption = "株価ロード"
.OnAction = "Macro1"
End With
サブメニュー追加
.Controls.Add Type:=msoControlPopup
With .Controls(2)
.Caption = "その他"
.Controls.Add Type:=msoControlButton
.Controls(1).Caption = "シート保護"
.Controls(1).OnAction = "シート保護"
.Controls.Add Type:=msoControlButton
.Controls(2).Caption = "シート保護解除"
.Controls(2).OnAction = "保護解除"
.Controls.Add Type:=msoControlButton
.Controls(3).Caption = "HTMLファイル作成"
.Controls(3).OnAction ="Macro1"
' .Controls(3).OnAction = "C:\サンプル\KIweb\KIweb.xls!chengs"
End With
End With
End Sub
|
| Sub シート保護() ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True MsgBox "シートにプロテクトを掛けました" End Sub |
| Sub 保護解除() ActiveSheet.Unprotect MsgBox "シートにプロテクトを解除しました" End Sub |
Sub test1() ' Application.Run "C:\サンプル\KIweb\KIweb.xls!chengs" ' Application.Run "KIweb.xls!chengs" ' Call chengs End Sub |
Const zikan As Date = "0:00:01"
Dim kurikaesitm As Date
Sub 連続1()
Call 連続1a
kurikaesitm = Now + TimeValue(zikan)
Application.OnTime kurikaesitm, "連続1"
End Sub<
--------------------------------------------------------
Sub 連続1a()
Cells(3, 3) = Int((56 + 1) * Rnd + 1)
Cells(3, 3).Interior.ColorIndex = Cells(3, 3).Value
End Sub
--------------------------------------------------------
Sub 連続中止()
On Error Resume Next
Application.OnTime kurikaesitm, "連続1", , False
MsgBox "プロシジャ[連続1]の実行を中止しました"
On Error GoTo 0
End
End Sub
|
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetAsyncKeyState Lib "User32.dll" _
(ByVal vKey As Long) As Long
Dim tima As Long, tmae As Long
Dim byo As Integer, kystop As Integer, clrm As Integer
Sub 連続2()
kystop = 0
Do
byo = 0
Do
DoEvents
tima = GetTickCount
If tima - tmae >= 1000 Then
tmae = tima
byo = 1
End If
If GetAsyncKeyState(40) < 0 Then
kystop = 1
Exit Do
End If
If byo = 1 Then
Exit Do
End If
Loop
If kystop = 1 Then
Exit Do
End If
Call 連続2a
Loop
MsgBox "プロシジャ[連続2]の実行を中止しました"
End Sub
--------------------------------------------------------
Sub 連続2a()
Cells(7, 3) = Int((56 + 1) * Rnd + 1)
Cells(7, 3).Interior.ColorIndex = Cells(7, 3).Value
End Sub
|
Sub test1() ' Application.Run "C:\サンプル\KIweb\KIweb.xls!chengs" ' Application.Run "KIweb.xls!chengs" ' Call chengs End Sub |