0
0

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 3 years have passed since last update.

Excelのvbaから、Outlookを操作して、「分類」を、まとめて設定するやり方です。

Posted at

Excelのvbaから、Outlookを操作して、
「分類」を、まとめて設定するやり方です。

code1.bas
Private Sub CommandButton1_Click()

    If MsgBox("Outlookの分類をすべて削除します (止める場合はキャンセル)", vbOKCancel) = vbOK Then
        Application.Cursor = xlWait
        Call ぜんぶ削除
        Application.Cursor = xlDefault
        MsgBox "削除しました"
    End If

End Sub

Private Sub CommandButton2_Click()

    If MsgBox("Outlookの分類を登録します (止める場合はキャンセル)", vbOKCancel) = vbOK Then
        Application.Cursor = xlWait
        Call ずんずん追加
        Application.Cursor = xlDefault
        MsgBox "登録しました"
    End If

End Sub

設定用のエクセルシートでは、
main0という名のシートを用意し、
1行目から35行目(※一旦の上限)までに、
1列目:分類名
2列名:色
を入力して、実行する。

code2.bas
Sub ぜんぶ削除()

    Set myol = CreateObject("Outlook.Application")

    Dim Ns As Outlook.Namespace
    Set Ns = myol.GetNamespace("MAPI")
    Dim olCats As Categories
    Dim olCat As Outlook.Category
    Dim olCatCon As Outlook.CategoryRuleCondition

    For Each olCat In Ns.Categories
        'Debug.Print olCat.Name, olCat.Color
        myol.Session.Categories.Remove (olCat.Name)
    Next

    Set Ns = Nothing
    Set myol = Nothing
End Sub



Sub ずんずん追加()

    Set myol = CreateObject("Outlook.Application")

    Dim Ns As Outlook.Namespace
    Set Ns = myol.GetNamespace("MAPI")
    Dim olCats As Categories
    Dim olCat As Outlook.Category
    Dim olCatCon As Outlook.CategoryRuleCondition

    For i = 1 To 35
        If Sheets("main0").Cells(i, 1).Value <> "" Then
            myol.Session.Categories.Add Sheets("main0").Cells(i, 1).Value, CInt(Sheets("main0").Cells(i, 2).Value)
        End If
    Next

    Set Ns = Nothing
    Set myol = Nothing

End Sub

単に参考、色の意味

color.bas
'olCategoryColorNone	0
'olCategoryColorRed	1
'olCategoryColorOrange	2
'olCategoryColorPeach	3
'olCategoryColorYellow	4
'olCategoryColorGreen	5
'olCategoryColorTeal	6
'olCategoryColorOlive	7
'olCategoryColorBlue	8
'olCategoryColorPurple	9
'olCategoryColorMaroon	10
'olCategoryColorSteel	11
'olCategoryColorDarkSteel	12
'olCategoryColorGray	13
'olCategoryColorDarkGray	14
'olCategoryColorBlack	15
'olCategoryColorDarkRed	16
'olCategoryColorDarkOrange	17
'olCategoryColorDarkPeach	18
'olCategoryColorDarkYellow	19
'olCategoryColorDarkGreen	20
'olCategoryColorDarkTeal	21
'olCategoryColorDarkOlive	22
'olCategoryColorDarkBlue	23
'olCategoryColorDarkPurple	24
'olCategoryColorDarkMaroon	25
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?