Excel VBA – 应用程序调用者范围无法定义

我有一个列表,其中包含名称和电子邮件地址的列,后面跟着另一列,用“发送电子邮件”button启动下面的macros。

macros应该通过application.caller函数来拉取当前行的位置,然后将行号与预定义的列号相结合,以便在填充我的电子邮件元素之前成功拉取名字,姓氏,电子邮件地址。 这似乎没有工作,因为application.caller返回empty ,因此当按下发送电子邮件button没有单元格/行信息传递。

代码如下:

 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个办公版本的语言差异的问题。 英文复制工作正常,但中文复制要求我删除button,并重新创build它们。 据我所知,这是由于英文版将形状标识为(矩形形状XXX),而中文将其标识为UTF 8字符。

删除形状并重新创buildbutton做了诀窍。

你确定application.caller正在返回空吗? 因为这似乎不太可能。 在程序types的开始

 debug.print application.caller 

点击button,不要使用F8或F5运行它。 你应该能够看到立即窗口中的值。 另外我使用ActiveXbutton时遇到了奇怪的问题。 尝试将其更改为正常button。 除非我们看看工作本身,否则难以说明为什么会出现这个问题。