- 帖子
- 31
- 主題
- 6
- 精華
- 0
- 積分
- 59
- 點名
- 0
- 作業系統
- win 7
- 軟體版本
- office 2007
- 閱讀權限
- 20
- 性別
- 女
- 註冊時間
- 2013-4-4
- 最後登錄
- 2013-9-2
|
謝謝stillfish、是用反了,可是現在有另一個問題;資料有兩個人同時要接收時,程式判讀只會將最後一位列在收件者上面,請問這是哪個部份有誤?
另外請問夾帶檔案位置的部份一直測試不出來是語法錯誤嗎?謝謝- Sub SEND()
- Dim OutApp As Object
- Dim OutMail As Object
- Dim FileName As String
- Dim EmailTo As String
- Dim EmailCC As String
- Dim EmailBCC As String
- Dim EmailSubject As String
- Dim EmailBody As String
- Dim cell As Integer
-
- SendType = CStr(Sheets("Sheet2").Cells(2, 2))
- If SendType = "1" Then
- cell = 8
- ElseIf SendType = "2" Then
- cell = 9
- ElseIf SendType = "3" Then
- cell = 10
- ElseIf SendType = "4" Then
- cell = 11
- Else
- cell = 0
- End If
- If cell > 0 Then
- For i = 4 To 6 Step 1
- If CBool(Sheets("Sheet2").Cells(i, cell)) = "TRUE" Then
- EmailTo = CStr(Sheets("Sheet2").Range("G" & i)) & ";"
- End If
- Next
- EmailCC = CStr(Sheets("Sheet2").Range("G" & 7))
- EmailBCC = CStr(Sheets("Sheet2").Range("G" & 8))
- EmailSubject = CStr(Sheet2.Cells(2, 3))
- EmailBody = CStr(Sheet1.Range("A" & 11)) & vbNewLine
-
- 'If [Sheet1].Cells(8, 1) <> "" Then .AddAttachment ([Sheet1].Cells(8, 1))
- If EmailCC <> "" Then
- Set rng = Sheets("Sheet1").Range("A11:G30").SpecialCells(xlCellTypeVisible)
- On Error Resume Next
- ' Only send the visible cells in the selection.
- 'Set rng = Selection.SpecialCells(xlCellTypeVisible)
- On Error GoTo 0
- If rng Is Nothing Then
- MsgBox "The selection is not a range or the sheet is protected. " & _
- vbNewLine & "Please correct and try again.", vbOKOnly
- Exit Sub
- End If
- With Application
- .EnableEvents = False
- .ScreenUpdating = False
- End With
- Set OutApp = CreateObject("Outlook.Application")
- Set OutMail = OutApp.CreateItem(0)
-
- On Error Resume Next
- On Error GoTo 0
- With OutMail
- .To = EmailTo
- .CC = EmailCC
- .BCC = EmailBCC
- .Subject = EmailSubject
- .body = EmailBody
- ' .attachments.Add
- .display
- End With
- With Application
- .EnableEvents = True
- .ScreenUpdating = True
- End With
- Set OutMail = Nothing
- Set OutApp = Nothing
- End If
- End If
- End Sub
複製代碼 |
|