2016-09-26 4 views
0

このコードは、メール添付ファイルを改善するためのものです。複数の受信者を.To.CCに含めることを試みました。私はいくつかのコードを見つけましたが、SendMessageを動作させることができませんでした。これは、SendMessage機能を示している関数を呼び出す際にエラーが発生しました:引数が間違っているか、プロパティの割り当てが無効です

Wrong number of arguments or invalid property assignment 

Sub sendmail() 
Dim Source As Document, Maillist As Document, TempDoc As Document 
Dim mysubject As String, message As String, title As String 
Dim datarange As Range 
Dim body As String 
Dim recips As Variant 
Dim ccs As Variant 
Dim bccs As Variant 
Dim j As Integer 
Dim attachs As Variant 
Set Source = ActiveDocument 
With Dialogs(wdDialogFileOpen) 
    .Show 
End With 
Set Maillist = ActiveDocument 
' Show an input box asking the user for the subject to be inserted into the email messages 
message = "Enter the subject to be used for each email message." ' Set prompt. 
title = " Email Subject Input" ' Set title. 
' Display message, title 
mysubject = InputBox(message, title) 
' Iterate through the Sections of the Source document and the rows of the catalog mailmerge document, 
' extracting the information to be included in each email. 

'IMPORTANT: This assumes your email addresses in the table are separated with commas! 
For j = 0 To Source.Sections.Count - 1 
    body = Source.Sections(j).Range.Text 
    'get to recipients from tables col 1 (I'd prefer this in excel, it's tables are much better!) 
    Set datarange = Maillist.Tables(1).Cell(j, 1).Range 
    datarange.End = datarange.End - 1 
    recips = Split(datarange.Text) 
    'CC's 
    Set datarange = Maillist.Tables(1).Cell(j, 2).Range 
    datarange.End = datarange.End - 1 
    ccs = Split(datarange.Text) 
    'BCC's 
    Set datarange = Maillist.Tables(1).Cell(j, 3).Range 
    datarange.End = datarange.End - 1 
    bccs = Split(datarange.Text) 

    'Attachments array, should be paths, handled by the mail app, in an array 
    ReDim attachs(Maillist.Tables(1).Columns.Count - 3) 'minus 2 because you start i at 2 and minus one more for option base 0 
    For i = 2 To Maillist.Tables(1).Columns.Count 
     Set datarange = Maillist.Tables(1).Cell(j, i).Range 
     datarange.End = datarange.End - 1 
     attachs(i) = Trim(datarange.Text) 
    Next i 

    'call the mail sender 
    SendMessage recips, Subject, body, ccs, bccs, False, attachs 
    Next j 
Maillist.Close wdDoNotSaveChanges 
MsgBox Source.Sections.Count - 1 & " messages have been sent." 
End Sub 

エラーです。 SendMessage recips、Subject、body、ccs、bccs、False、attachs

+0

あなたの質問に追加するpost、エラーとエラーを生成する行。 SendMessageのコードも参考になるでしょう。 – niton

+0

@niton SendMessage関数で「間違った引数または無効なプロパティの割り当て」エラーが表示されています。 'SendMessage recips、Subject、body、ccs、bccs、False、attachs' –

答えて

1

"SendMessage関数"に表示されていないコードは、この行と同じ数の引数(パラメータ)を受け入れる必要があります。

マッチング7つの引数になり
'call the mail sender 
SendMessage recips, Subject, body, ccs, bccs, False, attachs 

:名前が同じである可能性が

Function SendMessage (fnrecips, fnSubject, fnbody, fnccs, fnbccs, fnFalse, fnattachs) 

:それは次のようになり recips、件名、本文、CCS、BCCが、虚偽、attachs

ご希望の場合。

+0

@nitonに感謝してコードを試してください –

関連する問題