我有一个列表,其中包含名称和电子邮件地址的列,后面是另一列,其中包含“发送电子邮件”按钮以启动下面的宏。
宏应该通过application.caller
函数拉出当前行的位置,然后将行号和预定义的列号组合成成功拉取我的电子邮件之前的名字,姓氏,电子邮件地址元素。这似乎不再起作用application.caller
返回empty
,因此当按下发送电子邮件按钮时,不会传递单元格/行信息。
以下代码:
Sub Mail_ThankYouNote()
'Working in 2000-2010
Dim OutApp As Object
Dim outMail As Object
Dim rng As Range
Dim lastrow, nationality, SentDate, EmailCount, Title, MailTO, LangStatus As Range
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
ActiveWorkbook.Sheets("Data").Select
' check if outlook is open, if not launch application
Call CheckOutlook
' define column locations for nationality, sent-date, email count, title
Set OutApp = CreateObject("Outlook.Application")
Set outMail = OutApp.CreateItem(0)
Set caller_button = ActiveSheet.Cells(ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row, 14)
Set nationality = ActiveSheet.Cells(ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row, 7)
Set SentDate = ActiveSheet.Cells(ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row, 13)
Set EmailCount = ActiveSheet.Cells(ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row, 15)
Set Title = ActiveSheet.Cells(ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row, 8)
Set MailTO = ActiveSheet.Cells(ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row, 12)
MsgBox caller_button, vbOKOnly, "Info"
' check if title is empty
If Title = "" Then
MsgBox "The guest title is empty, please fill in a title before sending the post stay email.", vbOKOnly, "No title"
Exit Sub
End If
真的不确定导致这种情况的原因是因为它之前的工作......
感谢任何帮助。 A2K
修改 事实证明这是与我的2个办公室版本的语言差异有关的问题。英文副本工作正常,但中文副本要求我删除按钮并重新创建它们。据我所知,这是因为英文版将形状识别为(矩形形状XXX),而中文将其识别为UTF 8字符。
删除形状并重新创建按钮就可以了。
答案 0 :(得分:2)
你确定application.caller返回空吗?因为这似乎不太可能。在程序开头输入
debug.print application.caller
然后单击按钮,不要使用F8或F5运行它。您应该能够在即时窗口中看到该值。此外,我在使用ActiveX按钮时遇到了奇怪的问题。尝试将其更改为普通按钮。除非我们看一下工作簿本身,否则很难说为什么会出现这个问题。