使用pdf附件通过Gmail发送电子邮件的VBA代码 [英] VBA code to send email through gmail with pdf attachment

查看:213
本文介绍了使用pdf附件通过Gmail发送电子邮件的VBA代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码已经在工作,但不是100%...我想通过Gmail发送一封电子邮件,附带PDF格式...但是我不想要一个特定的pdf文件。

I have this code that is already working, but not 100%... I would like to send an email through Gmail with a pdf attached... But I don´t want a specific pdf file.

我知道我可以在代码上放置一个特定的文件名,但是我的pdf文件总是改变名称

I know I can put a specific file name on the code, but my pdf files always change the name

例如:
Clientname_1.pdf,Clientmane_2.pdf,Suppliername_1.pdf等



The code I have is this, but does not work:

Dim objEmail, objConfig
Set objEmail = CreateObject("CDO.Message")

objEmail.From = "xpto@gmail.com"
objEmail.To =     Join(Application.Transpose(Sheets("Clients").Columns(7).SpecialCells(2)), ";")
objEmail.Subject = "Test"
objEmail.CC = ""
objEmail.AddAttachment "C:\Users\123\Desktop\*.pdf"

我需要将代码转到我想要的文件夹并发送现有的pdf文件(s)on ......

I need that the code go to the folder I want and send the existing pdf file(s) on it......

这段代码缺少什么???

What is missing in this code???

推荐答案

如果您只查找找到的第一个.PDF文件,那么类似这样的内容将是适当的。

If you are only looking for the first .PDF file found then something like this would be appropriate.

dim dr as string
dr = "C:\Users\123\Desktop\"
objEmail.AddAttachment dr & Dir(dr & "*.pdf")

Dir函数可以循环并找到所有适当的匹配,但似乎只有第一个匹配。如果Dir无法找到匹配的文件,它将返回一个零长度的字符串。

The Dir function could loop and find all appropriate matches but it seems that you only want the first one. If Dir cannot find a matching file it will return a zero-length string.

有关其他功能,您可能需要使用 Environ功能获取当前用户的配置文件文件夹并从那里获取他们的Desktop文件夹。

For additional functionality, you might want to use the Environ function to get the current user's profile folder and get their Desktop folder from there.

这篇关于使用pdf附件通过Gmail发送电子邮件的VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆