Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

VBA Create Outlook Calendar Entry automatically At Another Entry

I'm trying to write a small Outlook VBA Script which reads my Sharepoint Calendar Entries and then adds another One to my personal Calendar with an Offest of 4 hours on the same day. So far I got the following which successfully creates a new Entry but my For Each Loop doesnt seem to work as it always jumps back to the main Function when I try to create a new Entry with the Date and Time read from the Variable "newStart": Thats my Code so far:

Public newStart As String


Sub ReadEntries()
  Dim oApp As Outlook.Application

  On Error Resume Next
  ' check if Outlook is running
  Set oApp = GetObject("Outlook.Application")
  If Err <> 0 Then
    'if not running, start it
    Set oApp = CreateObject("Outlook.Application")
  End If


    Set olApp = New Outlook.Application
    Set olFldr = olApp.GetNamespace("MAPI").Folders("Other Calendars").Folders("FOLDERNAME")
    
    For Each Items In olFldr
        If olFldr.Items.Subject = "Given Entry Title" Then
            newStart = olFldr.Items.Start
            CreateStandby
          
        End If
    Next
            
Set oObject = Nothing
Set oApp = Nothing

End Sub


Sub CreateStandby()

 Dim standbyEntry As Object
 
 Set standbyEntry = Application.CreateItem(olAppointmentItem)
 standbyEntry.Subject = "New Entry Title"
 standbyEntry.Start = newStart
 standbyEntry.Duration = 240
 standbyEntry.BusyStatus = olOutOfOffice
 standbyEntry.Send
 standbyEntry.Save
 
End Sub

Any Help will be appreciated as I am just a beginner who wants to make his Life easier.

Best Regards!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...