1
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

よく使うVBA関数まとめ

Last updated at Posted at 2018-06-19

はじめに

しょっちゅう使いまわすVBA関数をまとめておく
気まぐれに増えます。たぶん。

シート関連

シート有無確認

' シートの有無を確認
Function IsExistSheet(targetName As String) As Boolean
    Dim ws As Worksheet
    IsExistSheet = False
    
    For Each ws In Worksheets
        If ws.Name = targetName Then
            IsExistSheet = True
        End If
    Next
End Function

指定したシートを削除

' シートを削除
Function DeleteSheet(targetName As String)
    Application.DisplayAlerts = False
    Worksheets(targetName).Delete
    Application.DisplayAlerts = True
End Function

図形関係

アクティブシートの図形をすべて削除

' 図形をすべて削除
Function DeleteAllShapes()
    ActiveSheet.Shapes.SelectAll
    Selection.Delete
End Function

ファイル関係

フォルダ選択

Function GetFolderPath() As String
    'フォルダ選択のダイアログボックスを開く
    Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
    If dlg.Show = False Then Exit Function
    '選択したフォルダのパス名を取得
     GetFolderPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
End Function

ファイル選択

Function GetFilePath() As String
    'ファイル選択のダイアログボックスを開く
    Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
    If dlg.Show = False Then Exit Function
    '選択したファイルのパス名を取得
     GetFolderPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
End Function
1
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?