我必须每天发送包含超链接的邮件。该链接指向每天创建的文件。
路径始终相同。
该文件将以当前日期作为名称(0316,0317,0318)。
我手动更改超链接中文件的名称。如何自动更新?是否可以将日期函数集成到超链接中?
我使用此代码:
Function GetBoiler(ByVal sFile As String) As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).openastextstream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
Sub Data_EMail()
Dim OLApp As Object
Dim OLMail As Object
Dim SigString As String
Dim Signature As String
Dim str_MsgBody As String
SigString = "C:\Users\Name\AppData\Roaming\Microsoft\Signatures\eForms.htm"
Signature = GetBoiler(SigString)
If Dir(SigString) = "" Then
MsgBox "No Signature Saved to C Drive to send Emails"
End If
Set OLApp = CreateObject("Outlook.Application")
Set OLMail = OLApp.CreateItem(0)
OLApp.Session.Logon
With OLMail
.To = ""
.CC = ""
.Subject = "Data " & Date
.HTMLBody = _
"<p>write your text here</p>" & _
"<a href=" & Chr(34) & "file://///...../0316.xlsx" & Chr(34) & ">Data</a>" & Signature
.Display
End With
Set OLMail = Nothing
Set OLApp = Nothing
End Sub
答案 0 :(得分:0)
类似的东西?使用
dateString = Format$(Month(Now), "00") & Format$(Day(Now), "00")
保存要添加到href中的日期字符串。我添加了一个调试语句来测试你的字符串(testString)=添加了变量的字符串。显然只对16/03有效。
不担心年份?多年来会发生什么?
注意:优化的类型函数格式$和使用&#34; 00&#34;填补零。
Option Explicit
Sub test()
Dim testString As String
testString = "<a href=" & Chr(34) & "file://///...../0316.xlsx" & Chr(34) & ">Data</a>"
Dim dateString As String
dateString = Format$(Month(Now), "00") & Format$(Day(Now), "00")
Debug.Print "<a href=" & Chr(34) & "file://///...../" & dateString & ".xlsx" & Chr(34) & ">Data</a>" '& Signature
Debug.Print "<a href=" & Chr(34) & "file://///...../" & dateString & ".xlsx" & Chr(34) & ">Data</a>" = testString
End Sub
答案 1 :(得分:0)
excel中的日期功能使这很简单
您可以使用Now()或使用Date()
获取当前日期和时间然后您可以使用日期格式从数字日拉出 日(DATE()) 使用Month(Date())
的月份和数字月份然后所要做的就是把它放在2位数的格式中,然后像这样将它们附加到另一个:
myDate = Date()
DateCode = Format(Day(myDate), "00") & Format(Month(myDate), "00")
fileName = "file://///...../" & DateCode & ".xlsx"