プログラミングのメモ

プログラミングの学び直し備忘録

VBA:Excel :App

画面更新

    Application.ScreenUpdating = True
    Application.ScreenUpdating = False

ファイルを開く
[ファイル]-[開く]-[参照]

  • 開く
  • 読み取り専用
  • コピー
  • 保護ビュー
  • 開いて修復...
'**
'* ファイル選択
'*
'* @param       {}
'* @param_ref   {}
'* @return      {}
'*
'* @note
'*
Public Function mthSelectFileDialog( _
                                    Optional sPath As String _
                                    ) As String

    Dim sRes As String

    '================================
    '// 初期フォルダ
    '================================
    If sPath = "" Then
        sPath = ThisWorkbook.Path
    End If
    
    If Not mFSO.FileExists(sPath) Then sPath = ThisWorkbook.Path
    
    '===========================================================
    '// ファイル選択(ダイアログ)
    '// https://excel-ubara.com/excelvba1/EXCELVBA376.html
    '===========================================================
    Dim fd As FileDialog
    
    '//
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .InitialFileName = sPath
        .ButtonName = "開く"
        .Filters.Clear
        .Filters.Add "Excelファイル", "*.xls"
    End With
    
    Dim lRet As Long
    lRet = fd.Show
    If lRet = 0 Then
        Set fd = Nothing
        Exit Function
    End If
    
    mthSelectFileDialog = fd.SelectedItems.Item(1)

End Function

R1C1参照形式
[ファイル]-[オプション]-[数式]-[数式の処理]
[R1C1参照形式]

    Application.ReferenceStyle = IIf(Application.ReferenceStyle = xlR1C1, xlA1, xlR1C1)

計算方法の設定
[ファイル]-[オプション]-[数式]-[計算方法の設定]

'**
'* 計算方法の設定
'*
'* Property Calculation As XlCalculation
'*    Excel.Application のメンバー
'*----------------------------------------------------------
'* Sub Calculate()
'*    Excel.Application のメンバー
'*
'* Sub Calculate()
'*    Excel.Worksheet のメンバー
'*
'* Function Calculate()
'*    Excel.Range のメンバー
'*
'*
'* parg     {}
'* @arg_ref {}
'* @arg_opt {}
'* @ret     {}
'*
'* @note
'*
Public Sub mthCalculation()
    
    '=============================
    '// Application
    '=============================
    Dim app As Application
    Set app = Application
    
    With app
        .Calculation = xlCalculationManual     '手動計算
        .Calculate                             '計算実行
        .Calculation = xlCalculationAutomatic  '自動計算
    End With

    '=============================
    '// WorkBook
    '=============================
    Dim wb As Workbook
    Set wb = app.Workbooks(ThisWorkbook.Name)
    With wb
    End With

    '=============================
    '// WorkSheet
    '=============================
    Dim ws As Worksheet
    Set ws = wb.Worksheets(wb.Sheets(1).Name)
    With ws
        .Calculate                             '計算実行
    End With
    
    '=============================
    '// Range
    '=============================
    Dim rng As Range
    Set rng = ws.Range(Cells(2, 1), Cells(10, 10))
    With rng
        .Calculate                             '計算実行
    End With
    
    
    Set ws = Nothing
    Set wb = Nothing
    Set app = Nothing
    
End Sub