2016-12-24 16 views
0

私は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 
+0

認識されているように、組み込みのテキストボックスコントロールはそれを行いません。 可能性があるのは、テキストボックスの変更イベント に応答して、コード内でテキストとフォーマットを取得することです。 – dgorti

+0

UserFormのDatePickerボックスを時間タイプのフォーマットに変更できるため、しかし今はそれはどちらもうまくいかないでしょう。私はそれがフォーマットではなく私が書いたコードかもしれないと思います。私は自分のすべてのコードで質問を編集します。 – gluc7

+0

@ gluc7「myStart As Date」はどこにありませんか? 'myStart = DTPicker1.value'にする必要があります。 'myStart = DTPicker1&DatePicker2'とは何でしょうか?これらの日付を一緒に追加しようとしていますか?正確には ? –

答えて

0

に提出するときにVBAでそのセルの書式を設定します。 myStartとmyEndの2つの変数をスペースで区切り、以下のコードに示すように "+"の代わりに "&"と接続する必要がありました。私はまた、適切にフォーマットするために、私の時間DTPickerでTimeValue関数を使う必要がありました。皆さんのご意見ありがとうございます!

Dim mysub 
    Dim myStart, myEnd As Date 
    mysub = TextBox1 
    myStart = DTPicker1 & " " & TimeValue(DTPicker2) 
    myEnd = DTPicker1 & " " & TimeValue(DTPicker3) 
    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 = .Subject 
     .ReminderSet = True 
     .BusyStatus = olBusy 
     .Categories = "Orange Category" 'add this to be able to delete the test appointments 
     On Error GoTo 0 
     .Save 'saves the new appointment to the default folder 
+0

素敵な仕事です、うれしいですね。 – pizzaslice

0

は、それが私だったら、私はUI日時のいずれかのまともな種類になるだろうと私は私のミスを見つけた見通し

Dim startDate 
Dim endDate 
startDate = Format(Range("A1").value, "yyyy-mm-dd") 
endDate = Format(Range("A2").value, "yyyy-mm-dd") 
' upload to outlook startDate, endDate, appointment details 
+0

私は細胞から情報を引き出しません。 Outlookに送信されるものはすべて、ユーザーフォームから直接送信されます。私は少しでも私の質問を変更しました。 – gluc7

関連する問題