|
|
|||||||||
| 本章では、ウインドウ操作(GUIに関わる部分)についてコードサンプルを示しながら説明しています。 | |||||||||
|
|||||||||
|
'Excelを最小化します
'現在のExcelの表示位置を取得 winTop = Application.Top
winLeft = Application.Left Application.WindowState = xlNormal Application.Left= -Application.Width 'Excelを元の位置に再表示 Application.Top = winTop Application.Left = winLeft |
|||||||||
|
|||||||||
|
|
'Excelを画面上で見えなくします Dim myTop As Double Dim myLeft As Double '現在のExcelの表示位置を取得 myTop = Application.Top myLeft = Application.Left 'Excelが最大化、もしくは最小化で表示されていたら処理を終了 If Application.WindowState <> xlNormal Then Exit Sub 'Excelを画面の表示領域外に表示 Application.Left = -Application.Width 'Excelを元の位置に再表示 Application.Top = myTop Application.Left = myLeft |
||||||||
|
|||||||||
| 'Excelをリサイズする Dim myTop As Double Dim myLeft As Double Dim myWidth As Double Dim myHeight As Double '現在のExcelの表示位置を取得 If Application.WindowState <> xlNormal Then 'Excelが最大化、もしくは最小化されている Else myLeft = Application.Left myTop = Application.Top myWidth = Application.Width myHeight = Application.Height End If If Application.WindowState = xlNormal Then Application.Left = 480 Application.Top = 85.75 Application.Width = 288.75 Application.Height = 356 End If 'Excel表示を元に戻す Application.Left = myLeft Application.Top = myTop Application.Width = myWidth Application.Height = myHeight |
|||||||||
|
|||||||||
| Tate = ActiveCell.Row Range(Cells(Tate + 1, 1), Cells(Tate + 5, 68)).Select With Selection.Borders(xlLeft) .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlRight) .Weight = xlThin .ColorIndex = xlAutomatic End With Selection.Borders(xlTop).LineStyle = xlNone With Selection.Borders(xlBottom) .Weight = xlThin .ColorIndex = xlAutomatic End With Selection.BorderAround LineStyle:=xlNone |
|||||||||
|
|
|||||||||
|
|||||||||
|
ActiveWindow.SplitRow = 13
ウインドウ分割を解除する ActiveWindow.SplitRow = 0 |
|||||||||
|
|||||||||
|
ActiveWindow.SplitColumn = 5
ウインドウ分割を解除する ActiveWindow.SplitRow = 0 |
|||||||||
|
|||||||||
|
Application.Caption = "ブルー スカイ予約システム
|
|||||||||
|
|||||||||
|
MenuBars(xlWorksheet).Menus.Add Caption:="バージョン情報(&M)"
MenuBars(xlWorksheet).Menus("バージョン情報(&M)").MenuItems.Add Caption:= "Ver.5" |
|||||||||
|
|||||||||
|
For Each mb In MenuBars
For Each mn In mb.Menus mn.Delete Next mn Next mb End Sub Sub すべてのメニュの状態を元にもどす() For Each mb In MenuBars mb.Reset Next mb 組み込みのメニュー バーを非表示にすることはできない(Excel95) |
|||||||||
|
|||||||||
| *Excel97以降で有効 Sub メニューバーを非表示にする CommandBars("Worksheet Menu Bar").Enabled = False 'メニューバーを元に戻す CommandBars("Worksheet Menu Bar").Enabled = True End Sub 参考1(メニュバーの構造) メニュバー メニュ メニュアイテム 参考2(メニュバーの種類は以下のようにたくさんある) Worksheet Menu Bar Chart Menu Bar Standard Formatting PivotTable Chart Reviewing Forms Stop Recording External Data Auditing Full Screen Circular Reference Visual Basic Web Control Toolbox Exit Design Mode Drawing Query and Pivot Workbook tabs Cell Column Row Cell Column Row Ply XLM Cell Document Desktop Nondefault Drag and Drop AutoFill Button Dialog Series Plot Area Floor and Walls Trendline Chart Formula Bar PivotTable Context Menu Query Query Layout AutoCalculate Object/Plot Title Bar (Charting) Layout WordArt Picture Shadow Settings 3-D Settings Borders Chart Type Pattern Font Color Fill Color Line Color Order Nudge Align or Distribute Rotate or Flip Lines Connectors AutoShapes Callouts Flowchart Block Arrows Stars & Banners Basic Shapes Shapes Inactive Chart Excel Control Curve Curve Node Curve Segment Pictures Context Menu OLE Object ActiveX Control WordArt Context Menu Rotate Mode Connector ウィザード(&W) Add Command Built-in Menus System |
|||||||||
|
|||||||||
| Dim myCB As CommandBar Dim myCBCtrl As CommandBarControl Set myCB = CommandBars("Worksheet Menu Bar") For Each myCBCtrl In myCB.Controls myCBCtrl.Delete Next myCBCtrl 'メニューバーを初期状態に戻す MenuBars(xlWorksheet).Reset End Sub |
|||||||||
|
|||||||||
| 新しいメニュー バーをアプリケーションに追加するには、Add メソッドを使います。 次の使用例は、新しいメニュー バーを追加し、それをアクティブにします。 With MenuBars.Add("株価市況") With .Menus.Add("ファイル") .MenuItems.Add "更新", "UpdateProc" .MenuItems.Add "印刷", "PrintProc" End With End With MenuBars("株価市況").Activate |
|||||||||
|
|||||||||
| [Visual Basic モジュール] メニュー バーに、新しいメニューアイテムを追加します。 MenuBars(xlModule).Menus.Add Caption:="詳細ヘルプ(&M)" 定数名 説明 xlWorksheet ワークシート、マクロ シート、ダイアログ シート xlChart グラフ xlModule Visual Basic モジュール xlNoDocuments ファイルが開かれていない状態 xlInfo 情報ウィンドウ xlWorksheetShort ショート ワークシート メニュー (Excel 3.1 互換) xlChartShort ショート グラフ メニュー (Excel 3.1 互換) xlWorksheet4 旧ワークシート メニュー バー (Excel 4.0 互換) xlChart4 旧グラフ メニュー バー (Excel 4.0 互換) |
|||||||||
|
|||||||||
| Worksheets("sheet1").Activate For col = 1 To MenuBars.Count Cells(1, col) = MenuBars(col).Caption For rw = 2 To MenuBars(col).Menus.Count + 1 Cells(rw, col) = MenuBars(col).Menus(rw - 1).Caption Next Next |
|||||||||
|
|||||||||
| [標準] ツールバーの先頭に新しいツールバー ボタンを追加し、 このボタンに myNewButtonMacro というマクロを登録します。 Set newButton = Toolbars("標準").ToolbarButtons.Add _ (Button:=210, Before:=1) newButton.OnAction = "myNewButtonMacro" 次の使用例は、すべてのツールバーをそれぞれの既定の状態に戻します。 For Each tb In Application.Toolbars tb.Reset Next tb |
|||||||||
|
|||||||||
| Worksheets("sheet1").Activate For col = 1 To Toolbars.Count Cells(1, col) = Toolbars(col).Name For rw = 2 To Toolbars(col).ToolbarButtons.Count + 1 Cells(rw, col) = Toolbars(col).ToolbarButtons(rw - 1).Name Next Next |
|||||||||
|
|||||||||
| Toolbars(1).Visible = False Toolbars(2).Visible = False With Application .ShowToolTips = False .LargeButtons = False .ColorButtons = False End With 'ツールバーを初期状態に戻す Toolbars(1).Visible = True Toolbars(2).Visible = True With Application .ShowToolTips = True .LargeButtons = False .ColorButtons = True End With |
|||||||||
|
|||||||||
| Sub すべてのツールバーを非表示にする() Dim col As Integer Worksheets("sheet1").Activate For col = 1 To Toolbars.Count Cells(col, 2) = "" If Toolbars(col).Visible = True Then Toolbars(col).Visible = False Cells(col, 2) = "True" '状態保存 End If Next End Sub Sub ツールバーの表示を元に戻す() Dim col As Integer Worksheets("sheet1").Activate For col = 1 To Toolbars.Count If Cells(col, 2) = "True" Then Toolbars(col).Visible = True '状態復帰 End If Next End Sub 参考(ツールバーの構造) ツールバー ツールバーボタン |
|||||||||
|
|||||||||
| Dim myCB As CommandBar 'エラーが発生しても処理を続行する On Error Resume Next For Each myCB In CommandBars myCB.Visible = False Next myCB 'エラーのトラップを無効にする On Error GoTo 0 'このバーだけは例外でEnabledでセットする CommandBars("Worksheet Menu Bar").Enabled = False 注意事項 元にもどす場合、 myCB.Visible = False を すべて True にして元にもどすと すべてのバーが表示されてしまう |
|||||||||
|
|||||||||
| Application.DisplayStatusBar = True Application.StatusBar = "処理 50% 終了しました" 'ステータスバーを表示しない Application.DisplayStatusBar = False |
|||||||||
|
|||||||||
| Application.SendKeys ("{TAB}") *ワークシート上のボタンにはFocusはない |
|||||||||
|
|||||||||
| SendKeys {TAB},true | |||||||||
|
|||||||||
| Dim myNo As Integer Dim myMsg As String,myTitle As String mymsg = "売上No.を指定してください" myTitle = "売上データ削除" myNo = Val(InputBox(Prompt:=myMsg, _ Title:=myTitle)) If myNo <> 0 Then MsgBox myNo & "を削除します" Else MsgBox "削除処理はキャンセルされました" End If |
|||||||||
|
|||||||||
| MsgBox "日付が入力されていません。" & Chr(13) & Chr(10) & _ "記録がない場合は、" & Date & "を入力して下さい。" |
|||||||||
|
|||||||||
| Sub メッセージボックスのメッセージを途中で改行する() msgText = "現在のフォルダ:" & Chr(13) & CurDir() MsgBox msgText End Sub Sub Dialog1 のリスト ボックス 1 の選択項目を、英字の A から Z に設定する() For i = 65 To 90 DialogSheets("Dialog1").ListBoxes(1).AddItem Text:=Chr(i) Next i End Sub Chr(9) タブ Chr(10) ライン フィード文字 Chr(13) キャリッジ リターン |
|||||||||
|
|||||||||
| ActiveSheet.DrawingObjects("テキスト 4").Select Selection.Left = 109.5 Selection.Top = 33 位置の単位は、ポイント (1 ポイントは、1/72 インチ、0.35 mm) |
|||||||||
| ご意見・ご感想をお寄せください。info@beagle-hc.com ‖ このサイトについて | |||||||||
| Copyright 2006 - 2009 uTRAM Corp. All Rights Reserved | |||||||||