Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-18-2015, 02:34 PM
komobu komobu is offline Create Calendar Item though VBA Windows XP Create Calendar Item though VBA Office 2003
Advanced Beginner
Create Calendar Item though VBA
 
Join Date: Feb 2011
Posts: 34
komobu is on a distinguished road
Default Create Calendar Item though VBA

Hi;



I would like to create a calendar item through vba so that much of my items will already be filled in. I also want to increase the font size in the item.

I am hoping to click on an icon in the ribbon (Which will run a macro), and a macro will create a new event with the subject of "Vehicle Inspection", Start Time would be current date & Time (Nearest 1/2hour), The default duration would be one hour and the AllDay Event would not be checked.

In the body of the calendar item I would like the font set to arial 16, and these 3 lines:

VIN:
Od:
Plate:

is this possible?

Any help would be appreciated.
Reply With Quote
  #2  
Old 11-18-2015, 10:12 PM
gmayor's Avatar
gmayor gmayor is offline Create Calendar Item though VBA Windows 7 64bit Create Calendar Item though VBA Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following macro and function will do that. You will have to add the button to the context sensitive Calendar ribbon. Remove the apostrophe from the start of the line where indicated after testing, (unless you want to add to the body of the appointment item)

Code:
Option Explicit

Sub CreateAppointment()
Dim strStartTime As String
Dim strEndTime As String
    strStartTime = Format((Round(Now() * 48, 0) / 48), "hh:mm")
    strEndTime = Format(DateAdd("n", 60, CDate(strStartTime)), "hh:mm")
    AddOutlookApptmnt Date, Date, strStartTime, strEndTime, "Vehicle Inspection", "VIN:" & vbCr & vbCr & "Od:" & vbCr & vbCr & "Plate:"
lbl_Exit:
    Exit Sub
End Sub


Private Sub AddOutlookApptmnt(sStartDate As String, _
                              sEndDate As String, _
                              sStartTime As String, _
                              sEndTime As String, _
                              sSubject As String, _
                              sBody As String, _
                              Optional sLocation As String)

Dim objAppt As Outlook.AppointmentItem
Dim objInsp As Outlook.Inspector
Dim objDoc As Object
Dim oRng As Object
Dim datStartDate As Date
Dim datEndDate As Date
Const BodyFont As String = "Arial"
Const BodySize As Long = 16
    datStartDate = CDate(sStartDate & " " & sStartTime)
    datEndDate = CDate(sEndDate & " " & sEndTime)

    Set objAppt = CreateItem(1)        'appointment
    With objAppt
        .Start = datStartDate
        .End = datEndDate
        .ReminderSet = True
        .AllDayEvent = False
        .Subject = sSubject
        .Location = sLocation
        .Display
        Set objInsp = objAppt.GetInspector
        Set objDoc = objInsp.WordEditor
        Set oRng = objDoc.Range(0, 0)
        oRng.Text = sBody
        oRng.Font.Name = BodyFont
        oRng.Font.Size = BodySize
        .BusyStatus = 0
        'objInsp.Close 0 ' reinstate when you are happy with the result
    End With
CancelledByUser:            'Error handler
    If Err.Number > 0 Then
        MsgBox "Cancelled By User", , "Operation Cancelled"
    End If
    Set objAppt = Nothing
    Set objInsp = Nothing
    Set objDoc = Nothing
    Set oRng = Nothing
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-19-2015, 07:47 AM
komobu komobu is offline Create Calendar Item though VBA Windows XP Create Calendar Item though VBA Office 2003
Advanced Beginner
Create Calendar Item though VBA
 
Join Date: Feb 2011
Posts: 34
komobu is on a distinguished road
Default

Hi Graham;

This looks great! Thanks you so very much.
Reply With Quote
  #4  
Old 11-19-2015, 08:44 AM
komobu komobu is offline Create Calendar Item though VBA Windows XP Create Calendar Item though VBA Office 2003
Advanced Beginner
Create Calendar Item though VBA
 
Join Date: Feb 2011
Posts: 34
komobu is on a distinguished road
Default

Hi again Graham.

I am really thankful of the code you posted.

Not sure if this is possible, but is there a way to set the cursor position immediately after the "Vin: " instead of the "Location" field. If there isnt, no big deal. I was just wondering if there may be a way to do it.

Thanks again
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to open a template 12 times for a single document - create calendar wondermuse Word 2 12-30-2014 02:58 AM
Create calendar in Powerpoint 2010 anhnha PowerPoint 17 09-23-2014 11:40 PM
Help! Need VBA solution to create CSV file and export to Google Calendar mister_audioman Excel Programming 0 01-12-2012 01:07 PM
Create Calendar Item though VBA Create calendar event groegee Outlook 1 12-05-2011 09:56 PM
How do you update existing Outlook calendar item from Word with macro? Joe Patrick Word VBA 0 07-09-2011 05:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft