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?

【excelVBA(python)×Teams】特定チャネルにメッセージ投稿する

Posted at

ExcelVBAからの実行でExcelファイルをteamsの特定チャネルにメッセージ投稿する方法。
―使用するソフトやアプリケーションなど―
outlook
teams
excel(pythonでもok)

1.teamsの投稿したいチャネルのメールアドレスを取得
①チャネルの右の点三つをクリックし、「メールアドレスを取得」
uploading...0

2.コードの例

■VBA■

Sub send_email()
'Teamsにメッセージ投稿(ファイル付)
    Dim app As Object
    Dim otmail As Object
    Dim file1 As String

    file1 = "test_file.xlsx"	'ファイルのパス        
    Set app = CreateObject("Outlook.Application")
    Set otmail = app.createitem(0)	'メール新規作成
    
    With otmail
        .To = "1で取得したチャネルのメールアドレス"
        .Subject = "メッセージテスト"	'件名
        .body = "ファイルを投稿します。"	'本文
        .Attachments.Add file1	'ファイルの添付
	'.Display	'メールの表示
        .Send	'送信

    End With
    
    Set otmail = Nothing
    Set app = Nothing
    
End Sub

■python■

import win32com.client
import pythoncom
    
pythoncom.CoInitialize()
outlook=win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
mymail = outlook.CreateItem(0) 
file1='test_file.xlsx'	'ファイルのパス

mymail.To = '1で取得したチャネルのメールアドレス'
mymail.Subject='メッセージテスト' #件名
mymail.Body ='ファイルを投稿します。'	#本文
mymail.Attachments.Add(file1)	#ファイルの添付
#mymail.Display(True)	'メールの表示(Trueは表示)
mymail.Send()

pythoncom.CoInitialize()
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?