Change Outlook appointment series having a starting date in the past - vba

maybe you've experienced this, too. When I get involved into a project that is already running the project lead or scrumm master forward me appointment series like daily stand-ups or similar and the series started long before the day I receive the invitation.
Let's asume the following as example:
The series starts on January, 11th 2021 (Monday) and re-occurs every week.
I receive the invitation in my inbox on March, 16th 2021 (Tuesday).
When I look into my calender I will see this appointment in January, February etc. although I didn't participate back then because I wasn't assigned. To keep my calender in a way that it shows what really happend I have to manually remove all those occurances.
What I want to archieve is this:
The invitation enters my inbox.
Application_NewMailEx is triggered and runs a piece of VBA code that checks for a series like the following.
(...)
If TypeName(objInboxObject) = "MeetingItem" Then
Set objAppt = objInboxObject.GetAssociatedAppointment(False)
If Not objAppt Is Nothing Then
If objAppt.IsRecurring Then
Set objRecurrPatt = objAppt.GetRecurrencePattern
If Not objRecurrPatt Is Nothing Then
(...)
That's easy to handle but now the tricky part that I cannot find a solution anywhere and I really hope one of you can help me.
How I can I find out the NEXT FUTURE occurance starting from TODAY (the date I received it)? In the example this would be March, 22nd 2021. Especially if the re-occurance pattern is more complex than in the example.
Then I would replace the start date of the series with this calculated date and save the MeetingItem. If I accept it in the normal Outlook window I will have one calendar entries in the future and none in the past.

Analyzing the RecurrencePattern object you can find the date of the next occurrence. Then you can use the RecurrencePattern.GetOccurrence method which returns a specific instance of the AppointmentItem object on the specified date. The GetOccurrence method generates an error if no appointment of that series exists on the specified date.

Related

Is there a way to hide (and then show again) track changes in Word before a desired date?

I often have to check Word documents with multiple rounds of editing. To make things easier, I would like to be able to run a macro that prompts me to input a date and then any tracking before this date would be hidden, leaving only track changes made on or after the inputted date. Ideally, hitting the macro again would toggle the hidden track changes back to being shown.
I don't have an in-progress code as such, but do have two separate macros, each doing related things. The first is a simple toggle to hide and show insertions and deletions:
Sub ShowHideMarkup()
ActiveWindow.View.ShowInsertionsAndDeletions = Not _
ActiveWindow.View.ShowInsertionsAndDeletions
ActiveWindow.View.ShowFormatChanges = Not _
ActiveWindow.View.ShowFormatChanges
End Sub
And the second is one I've seen posted a few times online (created by Graham Mayor) - this one prompts for a date and then accepts earlier revisions:
Sub AcceptTrackingBeforeGivenDate()
Dim oRev As Revision
Dim oKeepDate As Date
Dim strRsp As String
While Not IsDate(strRsp)
strRsp = InputBox("Enter earliest date to keep", _
"Accept Changes Before Date", _
"1 Jan 2021")
If Len(strRsp) = 0 Then Exit Sub
Wend
oKeepDate = CDate(strRsp)
For Each oRev In ActiveDocument.Revisions
If oRev.Date < oKeepDate Then
oRev.Accept
End If
Next oRev
End Sub
I'm really not sure how to combine the two. Could anyone point me in the right direction?
Many thanks in advance!
Luke
Your two macros cannot be combined to do as you want. The:
first simply toggles the track-changes view on/off for all tracked changes.
second simply accepts all changes before a specified date, meaning they no longer exist in the document and, unless all the 'accepts' are undone or discarded (by not saving the document), provides no means of 'unhiding' those changes.
Word has no capacity to display some tracked changes and hide others based on the date.
The kludgy workaround I had in mind is equivalent to what the second macro does - without saving the modified document.
Do note that, even without using Track Changes, Word allows you to use its document comparison feature to compare two versions of the same document (e.g. the current version and a version in your backups). You could do the same thing by saving daily/weekly versions of the documents (different filenames, of course), to compare any two versions against each other.

How to see if a week past from a specific date?

I am making a VB.Net WinForm application. In which every week a setting will have to get reset and another setting(the date) will have to be updated.
For example:
The date is 7/17/18. On the 7/24/18, the setting will be reset and the date setting will be 7/24/18 so the function can go on. I know how to update and reset the setting. I just don't know how to say "a week from this date".
Thanks in advance for the help!
The easiest way would be to create an application level setting with user scope to store your last date, then you can compare the current date with the stored date to see if 7 days have past.
There are a few ways you could handle it, but to avoid culture issues, personally I have found that the easiest way is to store the date as a string in the international date format, so no matter what format the system uses for dates, the date will ALWAYS be in a recognisable format.
This method eliminates problems that could come up if the system's regional settings change:
My.Settings.DateSetting = Date.Today.ToString("yyyy-MM-dd")
To see if a week has passed from your previous date:
If Date.Today >= Cdate(My.Settings.DateSetting).AddDays(7) Then
'Do your stuff here
' ...
'Add one week to the previous date and save the setting
My.Settings.DateSetting = CDate(My.Settings.DateSetting).AddDays(7).ToString("yyyy-MM-dd")
My.Settings.Save()
End If

Outlook VBA: Compare every appointment date in a recurring pattern with spreadsheet data

I want to find out a way to compare every recurring appointment date in a recurrent pattern with the data in a spreadsheet using a loop, so as to create a irregular recurrent pattern. How can this be realized? thanks in advance.
The GetRecurrencePattern method of the AppointmentItem class returns a RecurrencePattern object that represents the recurrence attributes of an appointment. It provides the GetOccurrence method which returns a specific instance of the AppointmentItem object on the specified date. So, you can use the data listed on the spreadsheet and try to find a corresponding ocurrence in Outlook. Note, the GetOccurrence method generates an error if no appointment of that series exists on the specified date.
As Eugene mentioned, you can only pass a date to the GetOccurrence method in the Outlook Object Model, so it is your responsibility to figure out the days on which an appointment occurs - you will need to programmatically expand the recurrence pattern as well as use the RecurrencePattern.Exceptions collection to take into account modified occurrences.
You can of course loop through all dates in a given range and catch exceptions raised by GetOccurrence for the dates which the appointment does not occur.
If using Redemption is an option (I am its author), its implementation of the RDORecurrencePattern.GetOccurrence method allows to pass an integer index (as well as a date), which means you can simply loop through all recurrences (as long as it is not a recurrence with no end date).

VBA Excel 2003/2007: Declaring, Filling, and Passing a Jagged Array

I have thoroughly researched this topic and have yet to find code that works to accomplish what I need to do. In a nutshell, I'm creating a Production Tracking program and the feature of it on which I'm working now involves accurately tracking vacation days for 5 employees. A userform containing 5 listboxes, one for each employee, is used to select which days each employee took off for the week. The problem comes when I try to create unique dynamic arrays containing each employees' days off. I figured out how to create an array that captures this information but it's one array that gets reassigned each time the loop iterates. I need to have a unique array for each employee containing his days off to be used later in the code to adjust weekly scoring depending on his available days of work. Below is my code in the userform for to create a create the jagged array:
Public Name_Jagged() As Variant
For Each Name In Name_Array
Set Unique_Listbox = Controls(Name & "_Vacation")
For UnSelected = 0 To Unique_Listbox.ListCount - 1
If Unique_Listbox.Selected(UnSelected) = False Then
ReDim Preserve Name_Jagged(0 To UBound(Name_Jagged) + 1)
Name_Array(Name) = Name_Jagged()
Name_Jagged(UBound(Name_Jagged)) = Unique_Listbox.List(UnSelected)
End If
For UnSelected_Array_Pos = LBound(Name_Jagged) To UBound(Name_Jagged)
MsgBox Name & "_" & Name_Jagged(UnSelected_Array_Pos)
Next UnSelected_Array_Pos
Next UnSelected
Next Name
The compiler will not allow me to use Public Name_Jagged()() As Variant either despite most other forums saying this is how it's supposed to be written. The only other post I found online regarding this jagged array declaration issue was not answered.
I would really appreciate your help. I've been able to figure out everything so far from previous threads but this has eluded me. If there is a better option than jagged arrays to accomplish this, I'm all ears. I read in some forums about using Lists but I am not at all familiar with them or how to use them at this point. Thanks in advance for the help.
Just a thought but why have 5 static listboxes for each employee?
Why not just have 1 list box which contains the names of the employees and 1 list box which contains the days of the week. You highlight the employee you want and than select the days which they've taken off. Hit a submit button which would load the employees name into an array with the days selected? The array could be structured like this
NAME | MONDAY | TUESDAY | WEDNESDAY | THURSDAY | FRIDAY | SATURDAY | SUNDAY
JIM..... OFF............ OFF
ERIC.......................OFF.............OFF
And so on. This way if you need to add people in the future you just add them to the list box. You would than have one simple array to deal with?
Also you said "to be used later in the code to adjust weekly scoring depending on his available days of work"
A suggestion; You may want to consider logging it to a simple mysql/mssql database which gives you far more flexibility and control for the future.

Delete files that are not updated

Does anyone know if it is possible to delete a document that is not updated by a certain time. I am trying to make a blank inspection sheet repopulate every night at 12:01 AM and if no one enters in inspection information for that day, the form for that day be deleted so I don't have a surplus of blank inspection forms saved.
Yes it is possible. here is the base code. You need to change the if statement to reflect the correct time period.
Dim oFileObj
Set oFileObj = Wscript.CreateObject("WScript.FileSystemObject")
oFileObj.GetFile("File.Name")
if oFileObj.DateLastModified < NOW then
oFileObj.DeleteFile("File.Name")
end if
Set oFileObj = Nothing