私はOutlookの予定表に予定を作成するExcelでユーザーフォームを作成しています。開始時刻と終了時刻を除くすべてが機能しています。以下は私のコードです.DTPicker1は予定の日付で、DTPicker2とDTPicker3はそれぞれ開始時刻と終了時刻です。それらはdtpTime形式です。任命は正しい日付と主題で作成され、すべては時間を除いて正しく動作します。私がそれを修正するために何をすべきかわからない。どんな助けもありがとうございます。ありがとう!Excel VBA - 時間形式でユーザーフォームのテキストボックスを書式設定する方法
Private Sub CommandButton1_Click()
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
On Error Resume Next
Worksheets("Sheet1").Activate
Set olApp = GetObject("", "Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
On Error Resume Next
Set olApp = CreateObject("Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
MsgBox "Outlook is not available!"
Exit Sub
End If
End If
Dim mysub, myStart, myEnd
mysub = TextBox1
myStart = DTPicker1 & DatePicker2
myEnd = DTPicker1 & DatePicker3
Set olAppItem = olApp.CreateItem(olAppointmentItem) 'creates a new appointment
With olAppItem
'set default appointment values
.Location = ""
.Body = ""
.ReminderSet = True
.BusyStatus = olFree
.RequiredAttendees = ""
On Error Resume Next
.Start = myStart
.End = myEnd
.Subject = TextBox1
.Attachments.Add ("c:\temp\somefile.msg")
.Location = ""
.Body = ""
.ReminderSet = True
.BusyStatus = olBusy
.Categories = "Orange Category"
On Error GoTo 0
.Save 'saves the new appointment to the default folder
End With
Set olAppItem = Nothing
Set olApp = Nothing
MsgBox "Done !"
End Sub
認識されているように、組み込みのテキストボックスコントロールはそれを行いません。 可能性があるのは、テキストボックスの変更イベント に応答して、コード内でテキストとフォーマットを取得することです。 – dgorti
UserFormのDatePickerボックスを時間タイプのフォーマットに変更できるため、しかし今はそれはどちらもうまくいかないでしょう。私はそれがフォーマットではなく私が書いたコードかもしれないと思います。私は自分のすべてのコードで質問を編集します。 – gluc7
@ gluc7「myStart As Date」はどこにありませんか? 'myStart = DTPicker1.value'にする必要があります。 'myStart = DTPicker1&DatePicker2'とは何でしょうか?これらの日付を一緒に追加しようとしていますか?正確には ? –