0

以下に示すように、Excelシートから(学生名と彼のマーク)を含む各学生にメールを送信するように取り組んでいます

ここに画像の説明を入力

ここに画像の説明を入力

すべて正常に動作していますが、学生の名前がアラビア文字の場合。以下に示すように、名前は ( ???? ) として表示されます

ここに画像の説明を入力

ローカル システムの設定をアラビア語に変更しましたが、それでも同じ問題が発生します。

何かアドバイス?

4

2 に答える 2

0

@Super Symmetry 、本当にご協力ありがとうございます、まだエラーが発生します

ここに画像の説明を入力

私の現在のコード

 Sub SendMail()
    Dim objEmail

    Const cdoSendUsingPort = 2  ' Send the message using SMTP
    Const cdoBasicAuth = 1      ' Clear-text authentication
    Const cdoTimeout = 100      ' Timeout for SMTP in seconds

     mailServer = "smtp.gmail.com"
     SMTPport = 465     '25 'SMTPport = 465
     mailusername = "laggnaimtehan@gmail.com"
     mailpassword = "*****"
     ''''''''
     Dim n As Integer
     n = Application.WorksheetFunction.CountA(Range("c:c"))
     For i = 2 To n
     
     mailto = Range("c" & i).Value
     mailSubject = Range("e" & i).Value
     mailBody = "Hi " & Range("b" & i) & "," & vbCrLf & vbCrLf & _
               "Below you can find your marks:" & vbCrLf & vbCrLf & _
               "Math: - " & Range("F" & i) & vbCrLf & _
               "Network: - " & Range("G" & i) & vbCrLf & _
               "Physics: - " & Range("H" & i) & vbCrLf & _
               "Antenna: - " & Range("I" & i)

    Set objEmail = CreateObject("CDO.Message")
    Set objConf = objEmail.Configuration
    Set objFlds = objConf.Fields

    With objFlds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPport
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = cdoTimeout
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasicAuth
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailusername
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpassword
    .Update
    End With

    objEmail.To = mailto
    objEmail.From = mailusername
    objEmail.Subject = mailSubject
    objEmail.HTMLBodyPart.Charset = "utf-8"
    objEmail.HTMLBody = StringToHTML(mailBody)
    objEmail.TextBodyPart.Charset = "utf-8"
    objEmail.BodyPart.Charset = "utf-8"
    objEmail.Send

    Set objFlds = Nothing
    Set objConf = Nothing
    Set objEmail = Nothing
    Next i
  End Sub

   Function StringToHTML(sStr As String) As String
     sStr = Replace(sStr, Chr(10), "<br/>")
     sStr = Replace(sStr, Chr(13), "<br/>")
     sStr = Replace(sStr, Chr(11), "<br/>")
     StringToHTML = "<!doctype html><html lang=""en""><body><p>"
     StringToHTML = StringToHTML & sStr
     StringToHTML = StringToHTML & "</p></body></html>"
    End Function
 

前もって感謝します ....

于 2020-08-15T18:52:38.233 に答える