使用Outlook模板和设置变量从Excel 2007 VBA发送电子邮件(Send an email from Excel 2007 VBA using an Outlook Template & Set Variables)
我有一个数据列表,让我们说客户端信息(姓名,电子邮件,金额欠额等),存储在Excel工作表中。 我的目标是点击Excel中的按钮,并在Outlook模板中向每个客户端发送他们的信息。
- 创建一个邮件对象
- 将邮件对象设置为模板文件
- 设置然后用关于当前客户端的数据填充模板 - 大多停留在这里,不知道如何在模板中指定变量然后在VBA中与它们关联
- 保存到草稿供以后查看/发送
例如。 亲爱的<clientname> =亲爱的约翰史密斯
我的代码到目前为止:
Dim myOlApp As Outlook.Application Dim MyItem As Outlook.MailItem Set myOlApp = CreateObject("Outlook.Application") Set MyItem = myOlApp.CreateItemFromTemplate("C:\egTemplate.oft") With MyItem .To = Worksheets("Clients").Range(1, 2) .Subject = "Monthly bill" 'Refer to and fill in variable items in template .Save End With Set MyItem = Nothing Set MyOlApp = Nothing
我需要知道,如果这是可能的,我可以做到没有插件,如果是的话,有没有人知道我可以遵循的良好的链接/教程?
在此先感谢和亲切的问候
更新添加了我的代码并对请求进行了一些更改
I have a list of data, let's say client information (Name, Email, Amount Owing etc.), stored in an Excel worksheet . My aim is to click a button in Excel and send each client their information in an Outlook Template.
- create a mail object
- set the mail object to the template file
- setting and then filling in the template with data about the current client - mostly stuck here, not sure how to specify variables in a template and then relate to them in VBA
- save to drafts for later review/send
eg. Dear << clientname >> = Dear John Smith
My code thus far:
Dim myOlApp As Outlook.Application Dim MyItem As Outlook.MailItem Set myOlApp = CreateObject("Outlook.Application") Set MyItem = myOlApp.CreateItemFromTemplate("C:\egTemplate.oft") With MyItem .To = Worksheets("Clients").Range(1, 2) .Subject = "Monthly bill" 'Refer to and fill in variable items in template .Save End With Set MyItem = Nothing Set MyOlApp = Nothing
I need to know if this is even possible, can I do it without plugins and if so, does anyone know a good link/tutorial I can follow?
Thanks in advance and kind regards
Update Added my code and made some changes to the request
原文:https://stackoverflow.com/questions/8469960
最满意答案
在没有参数的情况下调用Date函数,始终返回浏览器的当前时间,该时间占用OS的时间和时区。
尝试这个:
var now = new Date(), first = new Date(now.getFullYear(), now.getMonth(), 1); alert(first);
您可以尝试使用
now.getTimezoneOffset();
查看时区now.getTimezoneOffset();
Calling the Date function without parameters, always return the current time for the browser, which takes the time and timezone from the OS.
Try this:
var now = new Date(), first = new Date(now.getFullYear(), now.getMonth(), 1); alert(first);
You can try to see the time zone using
now.getTimezoneOffset();
相关问答
更多-
保存的日期和时间与当前时区不同,如何解决?(Saved date and time is different with current time zone, how to fix it?)[2024-04-01]
根据您的评论,应用程序似乎将日期时间作为UTC时间写入数据库。 读取和显示时,应用程序会将其转换回您当地的时区。 您可能不想更改此行为。 有关更多信息,请查看此问题: WebMatrix Helper控制表在密码更改日期字段中显示错误时间 Based on your comment, it appears that the application is writing the datetime to the database as UTC time. When read and displayed, the ... -
如果只想显示给定区域的当前时间,则需要设置NSDateFormatter的timeZone属性: [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CST"]]; 如果要包含来自给定区域的时间的NSDate对象,则需要在检索该日期之前设置默认时区: NSDate* date = [NSDate date]; NSLog(@"%@", [date description]); [NSTimeZone setDefaultTimeZo ...
-
Rails如何保存和设置时区然后找到每个用户的当前日期?(Rails how to save and set time zone then find the current date for each user?)[2021-11-09]
@bill.trading_date = 6.hours.ago.in_time_zone().to_date @bill.trading_date = 6.hours.ago.in_time_zone( ).to_date -
使用AT TIME ZONE获得指定时区的当前时间(Using AT TIME ZONE to get current time in specified time zone)[2021-09-17]
代码的第一行包含错误: SELECT GETUTCDATE() AT TIME ZONE 'GMT Standard Time' GETUTCDATE()返回一个datetime时间,它没有时区偏移信息。 因此如MSDN文档中所述 : 如果提供的inputdate没有偏移量信息,则该函数应用时区的偏移量,假定在目标时区中提供了inputdate值。 因此,尽管您检索了UTC时间,但您错误地断言该值是在伦敦时间(UTC + 1表示夏令时在此日期)。 处理这个问题最简单的方法就是将UTC时间作为datetim ... -
在没有参数的情况下调用Date函数,始终返回浏览器的当前时间,该时间占用OS的时间和时区。 尝试这个: var now = new Date(), first = new Date(now.getFullYear(), now.getMonth(), 1); alert(first); 您可以尝试使用now.getTimezoneOffset();查看时区now.getTimezoneOffset(); Calling the Date function without parameters, a ...
-
你应该使用时间戳比较。 JS: var timestamp = (new Date()).getTime(); // send this to your php PHP: $timestampFromJs = intval($_GET["ts"]); // just made it up $ts = time() * 1000; // js timestamp is milliseconds if($ts - $timestampFromJs > 5000*60) ... 更新:如果您需要时区安全比较: ...
-
确定与Time.zone不同的时区中的日期(Determining the date in a timezone that is different than Time.zone)[2020-01-26]
只是不要使用Time.zone,使用服务器时间。 如果你只想让每个人24小时都一样,就不需要考虑用户认为是什么时间。 if Time.today == Time.local(year, month, day).to_date Just don't use the Time.zone, use server time. There isn't any need to get into what time the user thinks it is if you only want it to be the ... -
如何根据用户当前时区制作今天的日期方法?(How do I make a today's date method based on users current Time zone?)[2023-09-05]
您可以使用in_time_zone而不是更改in_time_zone : Time.current.in_time_zone(current_user.time_zone).to_date 您可能必须将时区作为方法参数传递,因为current_user通常在模型中不可用。 Instead of changing Time.zone, you could use in_time_zone: Time.current.in_time_zone(current_user.time_zone).to_date ... -
请尝试以下代码来获取缩写时区: var timeZoneAbbr = new Date().toString().replace(/^.*\(|\)$/g, "").replace(/[^A-Z]/g, ""); 我在这里的代码中找到了replace表达式。 此外, 这是一个测试小提琴。 Try the following code to get the abbreviated timezone: var timeZoneAbbr = new Date().toString().replace(/^.*\ ...
-
您从此调用中获取时区对象: [NSTimeZone localTimeZone] 您可以使用secondsFromGMT方法找出差异并使用时区创建日期。 您甚至可以为NSDate构建一个类别,其中包括将日期转换为当前时区日期的方法,这种方法甚至更简单。 You get the timezone object from this call: [NSTimeZone localTimeZone] And you can use the secondsFromGMT method to figure out ...