2016-09-26 2 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

게시물에 추가, 오류 및 오류를 생성하는 줄. SendMessage의 코드도 도움이 될 것입니다. – niton

+0

@niton SendMessage 함수에 "잘못된 인수 또는 잘못된 속성 할당"오류가 표시됩니다. 'SendMessage recips, Subject, body, ccs, bccs, False, attachs' –

답변

1

"SendMessage 함수"에 대해 표시하지 않은 코드는이 줄과 동일한 수의 인수 (매개 변수)를 받아 들여야합니다. 일치하는 일곱 개 인수 것

'call the mail sender 
SendMessage recips, Subject, body, ccs, bccs, False, attachs 

:

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

이름은 동일 할 수있다 : 제목 왕복동, 몸, CCS, BCC에, 거짓,

그것은처럼 보일 수 attachs 당신이 원하는 경우.

+0

@niton에 감사드립니다. 코드를 사용해보세요. –