Excel/VBAクリニック,今月の診断(7)自作ツールバーでマクロ実行を容易にする処方:ITpro
遅くなりすみません。フロート状態のメニューバーにボタンをつけてみました。こんな感じでどうでしょうか。
Sub MakeToolBar() Dim myBar As CommandBar Dim myButton As CommandBarControl Set myBar = Application.CommandBars.Add( _ Name:="名前入力", Position:=msoBarFloating) myBar.Visible = True Set myButton = myBar.Controls.Add( _ Type:=msoControlButton, ID:=1) With myButton .OnAction = "Sample1" .FaceId = 253 End With End Sub Sub Sample1() buf = InputBox("あなたのお名前は何ですか?") MsgBox (buf + "です。") With Selection .Font.Size = 40 '文字の大きさを指定 .TypeText (buf) End With End Sub Sub AutoOpen() Call MakeToolBar End Sub Sub RemoveToolBar() On Error Resume Next Application.CommandBars("名前入力").Delete On Error GoTo 0 End Sub Sub AutoClose() Call RemoveToolBar End Sub
Office TANAKA - Excel VBA(実は奥が深いInputBox)
上記URLをもとにマクロを書きました。
word2003でしか動作していませんが、おそらく2000でも動くと思います。
Sub Sample1() buf = InputBox("あなたのお名前は何ですか?") MsgBox (buf + "です。") With Selection .Font.Size = 40 '文字の大きさを指定 .TypeText (buf) End With End Sub
ありがとうございます。
できました。
このマクロを実行するボタンを常にポップアップウィンドウのような形で出しておくことはできないでしょうか。
Excel/VBAクリニック,今月の診断(7)自作ツールバーでマクロ実行を容易にする処方:ITpro
遅くなりすみません。フロート状態のメニューバーにボタンをつけてみました。こんな感じでどうでしょうか。
Sub MakeToolBar() Dim myBar As CommandBar Dim myButton As CommandBarControl Set myBar = Application.CommandBars.Add( _ Name:="名前入力", Position:=msoBarFloating) myBar.Visible = True Set myButton = myBar.Controls.Add( _ Type:=msoControlButton, ID:=1) With myButton .OnAction = "Sample1" .FaceId = 253 End With End Sub Sub Sample1() buf = InputBox("あなたのお名前は何ですか?") MsgBox (buf + "です。") With Selection .Font.Size = 40 '文字の大きさを指定 .TypeText (buf) End With End Sub Sub AutoOpen() Call MakeToolBar End Sub Sub RemoveToolBar() On Error Resume Next Application.CommandBars("名前入力").Delete On Error GoTo 0 End Sub Sub AutoClose() Call RemoveToolBar End Sub
コピーするだけで一発でできました!
どうもありがとうございます。もちろんいるかです。
コピーするだけで一発でできました!
どうもありがとうございます。もちろんいるかです。