我试图从Excel
中的userform
设置Outlook约会。如果我引用单元格,代码将起作用。如何参考userform
中的框?我还需要添加到我将从不同列表工作表中引用的会议的代码收件人。通过用户表单设置Outlook约会数据
下面是引用单元格在Excel中的代码工作通过单击工作表中的按钮:
Sub AddAppointments()
' Create the Outlook session
Set myOutlook = CreateObject("Outlook.Application")
' Start at row 2
r = 2
Do Until Trim(Cells(r, 1).Value) = ""
' Create the AppointmentItem
Set myApt = myOutlook.CreateItem(1)
' Set the appointment properties
myApt.Subject = Cells(r, 1).Value
myApt.Location = Cells(r, 2).Value
myApt.Start = Cells(r, 3).Value
myApt.Duration = Cells(r, 4).Value
' If Busy Status is not specified, default to 2 (Busy)
If Trim(Cells(r, 5).Value) = "" Then
myApt.BusyStatus = 2
Else
myApt.BusyStatus = Cells(r, 5).Value
End If
If Cells(r, 6).Value > 0 Then
myApt.ReminderSet = True
myApt.ReminderMinutesBeforeStart = Cells(r, 6).Value
Else
myApt.ReminderSet = False
End If
myApt.Body = Cells(r, 7).Value
myApt.Display
r = r + 1
Loop
End Sub
这是我尝试在改变引用框在一个窗体代码:
Private Sub Cmdappointment_Click()
Dim outlookapp As Object
'the mail item is the contents inside a mail
Dim mitem As AppointmentItem
'created outlook app
Set outlookapp = CreateObject("outlook.Application")
'it will open a new application
Set outlookapp = New Outlook.Application
'Set mail item
Set mitem = outlookapp.CreateItem(olMailItem)
Do Until userform2.TextBox4.Value = ""
' Create the AppointmentItem
Set myApt = myOutlook.CreateItem(1)
' Set the appointment properties
On Error Resume Next
mitem
myApt.Subject = Me.texbox4.Value
myApt.Location = Me.texbox3.Value
myApt.Start = Me.ComboBox1.Value
myApt.Duration = Me.ComboBox2.Value
' If Busy Status is not specified, default to 2 (Busy)
If Me.ComboBox3.Value = "" Then
myApt.BusyStatus = 2
Else
myApt.BusyStatus = Me.ComboBox3.Value
End If
If Me.TextBox1.Value > 0 Then
myApt.ReminderSet = True
myApt.ReminderMinutesBeforeStart = Me.TextBox1.Value
Else
myApt.ReminderSet = False
End If
myApt.Body = Me.TextBox2.Value
myApt.Display
End With
Loop
End Sub
你得到的错误是什么?我会建议评论'On Error Resume Next'这一行以知道抛出了什么错误,那么你将能够更轻松地继续。 – kaza
如果我在接下来的错误恢复发表评论,我得到的错误消息是:无效使用我的关键字。根据我的预约。主题 –
你去哪里,用'UserForm'明确引用替换所有'me'。 – kaza