Pandeng的专栏

Life is limited, but art is long

调试经验——将VBA代码粘贴到博客编辑器时中文字符丢失(显示为?号)的解决方法

发现从VBE复制粘贴代码到CSDN博客编辑器时,中文注释将丢失(显示为问号?),如下所示:

Sub ???????()
Dim cm As New CDO.Message
'Set cm = CreateObject("CDO.Message") '???????? '????·????C:\Windows\system32\cdosys.dll
cm.From = "1234567@qq.com" '???÷??????????"
cm.To = "649725266@qq.com,excelpx@163.com" '???????????????
cm.Subject = "????:???????????" '?趨?????????
'cm.TextBody =  '????????????????????????
cm.HtmlBody = "???????????^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" '???html??????????
cm.AddAttachment ThisWorkbook.path & "/a.xls"
stUl = "http://schemas.microsoft.com/cdo/configuration/" '???????????
With cm.Configuration.Fields
    .Item(stUl & "smtpserver") = "smtp.qq.com"         'SMTP?????????
    .Item(stUl & "smtpserverport") = 25                  'SMTP?????????
    .Item(stUl & "sendusing") = 2                        '??????
    .Item(stUl & "smtpauthenticate") = 1      '????????????????0?????           '
    .Item(stUl & "sendusername") = "1234567"                '?????????????
    .Item(stUl & "sendpassword") = "12345671"                  '?????????????
    .Update
End With
cm.Send '????????з?????
Set cm = Nothing
'???????????????
End Sub

解决方法:

将代码粘贴到新建的记事本,另存为时选择编码格式为“Unicode”,保存,然后从txt文件再复制一次代码,再粘贴到博客编辑器时就不会丢失中文字符了。

Sub 邮件发送()
Dim cm As New CDO.Message
'Set cm = CreateObject("CDO.Message") '创建对象 '引用路径:C:\Windows\system32\cdosys.dll
cm.From = "1234567@qq.com" '设置发信人的邮箱"
cm.To = "649725266@qq.com,excelpx@163.com" '设置收信人的邮箱
cm.Subject = "主题:邮件发送试验" '设定邮件的主题
'cm.TextBody =  '邮件正文,使用文本格式发送邮件
cm.HtmlBody = "邮件发送试验^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" '使用html格式发送邮件
cm.AddAttachment ThisWorkbook.path & "/a.xls"
stUl = "http://schemas.microsoft.com/cdo/configuration/" '微软服务器网址
With cm.Configuration.Fields
    .Item(stUl & "smtpserver") = "smtp.qq.com"         'SMTP服务器地址
    .Item(stUl & "smtpserverport") = 25                  'SMTP服务器端口
    .Item(stUl & "sendusing") = 2                        '发送端口
    .Item(stUl & "smtpauthenticate") = 1      '需要提供用户名和密码,0是不提供           '
    .Item(stUl & "sendusername") = "1234567"                '发送方邮箱名称
    .Item(stUl & "sendpassword") = "12345671"                  '发送方邮箱密码
    .Update
End With
cm.Send '最后当然是执行发送了
Set cm = Nothing
'发送成功后即时释放对象
End Sub

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hpdlzu80100/article/details/80687203
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭