1

「計画用のホーム オーディオ (2013 年 3 月 28 日)」という名前の Excel ファイルがあります。

日付は毎日変わりますが、テキストは同じです。

これらのファイルを Outlook に添付するにはどうすればよいですか?

Sub Test()

    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hello World!"

        .Attachments.Add ("C:\Users\Desktop\Today\Home Audio for Planning   (28-3-2013).xlsx")

        .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

End Sub
4

5 に答える 5

7

以下のコードを試してください: strLocation は動的に生成されます。この変数を添付ファイルに渡すだけです。生成されるファイル名はHome Audio for Planning_28-03-2013.xlsx のようになります。

Sub Test()
    Dim strLocation As String

    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hello World!"

        strLocation = "C:\Users\Desktop\Today\Home Audio for Planning" & Format(Now(), "_DD-MM-YYYY") & ".xlsx"
        .Attachments.Add (strLocation)
        .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

End Sub
于 2013-03-28T06:53:00.187 に答える
1

簡単、

  .Attachments.Add ("C:\Users\Desktop\Today\Home Audio for Planning (" & FORMAT(DATE,DD-MM-YYYY)") 
于 2014-10-22T11:56:57.600 に答える
0

添付ファイル名を動的に変更しようとしましたか。例えば;

.Attachments.Add ("C:\Users\Desktop\Today\Home Audio for Planning   (" + timeVariable  + ").xlsx")

必要な形式の日付の日付と一致するように、前に時間変数を設定できます。

乾杯

于 2013-03-28T06:22:20.137 に答える