Programatically Show/Hide the FROM field in Outlook using c# - outlook-addin

Is there any way to show/hide the FROM field in Outlook programatically?
The reason I want to do this, is because some code i've wrote so far successfully sets the FROM field.
However, after the first time it is ran, the FROM field is set, but the UI doesn't reflect this change.
Hiding and then re-showing the FROM field forces the UI to update. Ideally I want to find a way to do this in both 2007 and 2010.
If it isn't possible to hide and re-show the FROM field programatically is there any other way to force the UI to refresh?
//Get the explorer window and the currently selected item
Explorer activeExplorer = this.Application.ActiveExplorer();
MailItem origMsg = activeExplorer.Selection[1];
Recipients origRecipients = origMsg.Recipients;
if (origRecipients.Count == 1)
{
AddressEntry address = origRecipients[1].AddressEntry;
currentMsg.Sender = address;
//currentMsg.SentOnBehalfOfName = origRecipients[1].Name; currentMsg.send
}

Related

Fire Subroutine when user leaves a date field ContentControl Word VBA

Edit: I've updated the post with more info.
I have a Content Control inside a header in Word in which I have a date time picker. I'm trying to fire the _ContentControlOnExit event when the user leaves the focus (blurs) of the picker.
Let's suppose I've manually created a Content Control and I've assigned it a Date Picker. I've also tagged it with the value date.
I want that each time the date is changed, I perform a subroutine that will insert a text value to another ContentControl tagged tide-level. I tried the code below with no success.
Please, note that the date ContentControl is inside a header in the Word Document.
Private Sub ActiveDocment_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
If (ContentControl.Type = wdContentControlDate) Then
MsgBox "Let's do it! Write the tide levels"
dateObj = ActiveDocument.SelectContentControlsByTag("tide-level")
dateObj.Range.Text = "wwwoohooo Tide Levels!"
Cancel = True
End If
End Sub
I remember reading somewhere that whenever you have content in the header, it seems things get problematic...
Any ideas?
P.S:
Currently using Word 365 - VBA
Based on the name of the procedure in the question - ActiveDocment_ContentControlOnExit - it appears the event handler was not generated automatically by Word and that it is therefore not in the ThisDocument class module of the document that contains the content controls. The name of the event handler (generated by the VBA editor) is usually Document_ContentControlOnExit.
The content control event handlers must be in ThisDocument. Theoretically, they could be typed manually, but Word doesn't always recognize manually typed event handlers. So it's better to use the VBA Editor's automatic "stub" generation to get the structures:
Open the ThisDocument module for the document that contains the content control.
In the code page window, at the top left, select "Document" from the drop-down.
from the top-right select the event to be inserted.
At this point, the VBA editor will create the "stub" for you - all that's needed is the code to be executed.
Note about the content control being in the header: This event does fire as long as focus when exiting remains in the header. If, however, the user double-clicks in the document body in order to exit the header the event doesn't fire. (At least, not in my tests.) If this is a problem you may want to put this field in the body of the document with a second, linked content control in the header to reflect the selection. Doing this is a bit complex (requires a Custom XML Part in the document to manage the linked information), but the version of Word you're using should have a tool for setting it up.
the macro name should be:
Docment_ContentControlOnExit
NOT:
ActiveDocment_ContentControlOnExit

Office Addin Custom Attributes on Range Text

I would like to know if it's possible to add additional attributes to simple Range text or Paragraph text from my Word Add-in. For simplicity see code below where I can populate the document with text but additionally i would like to store additional but behind the scenes info along with that text. Ultimately I want these read these custom attributes using the Open Xml SDK when these documents go through a processing stage.
private void AddAttributedContent(string documentContent)
{
var doc = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
var range = doc.Range();
range.Font.Size = 12;
range.Font.Name = "Calibri";
range.Underline = Word.WdUnderline.wdUnderlineSingle;
range.Text = documentContent;
// range.AddOpenXmlProperty("MyProp", "MyValue");
var para = doc.Paragraphs.Add();
para.Range.Text = documentContent;
//para.AddCustomProperty("MyProp", "MyVal");
}
Edit:
Ideally our property would sit inside of the resulting RunProprties :
No, you can't do that. You could probably do it with a content control or a text box though.
For a ContentControl, you could probably use Tag (if this is like sources, it probably has to be unique, though the description seems to imply it's meant for the purpose you need) or Title.
The Tag property is different from the Title property in that a tag is never displayed while a user edits a document. Instead, developers can use it to store a value for programmatic manipulation while the document is opened.
For a text box (a Shape), you could use AlternativeText or Title.
Note that altering Title (in both cases) or AlternativeText will probably affect the way the document is displayed if you save it as HTML.

How to set an Infragistics ribbon group visiblity to false in code

How to set an Infragistics ribbon group visiblity to false in code?
I am trying to hide an Infragistics group box depending on the users Dpi on form load.
There is a button inside the group area that I have managed to hide using:
utmApplicant.Tools("Match").SharedProps.Visible = False
I assumed I could use the same code to hide the group box but it keeps saying that the key has not been found but I am using the right key. Any suggestions?
I'm using VB.NET
It is not clear to what kind of object you are referring to.
In an Infragistics UltraToolbarsManager there is a Ribbon object that contains a Tabs collection. Each Tab contains a Groups collection and each Group contains one or more Tools.
So, to hide the first tab (I have used an integer to index, but the key string works as well)
utmApplicant.Ribbon.Tabs(0).Visible = False
To hide a specific group inside the first tab
utmApplicant.Ribbon.Tabs(0).Groups(0).Visible = False
To hide a particular tool assigned to a specific Group (a label, a button, a textbox or other kind of UI widgets) you could use this syntax
utmApplicant.Ribbon.Tabs(0)
.Groups(0)
.Tools("Match")
.InstanceProps.Visible = DefaultableBoolean.False
Tools are kept in the global collection under the UltraToolbarsManager hierarchy root but when assigned to a specific Group could be referenced with the syntax above.

ListView Not Displaying Added Text

Background:
Hello everyone, I'm not new to visual basic or programming. I just find it the fastest to make a GUI in visual basic for various programs; however, I'm having a recent issue.
I have a form with a ListView control that I populate using a textbox and a button.
the code I use for the button is:
Code:
listview1.items.add(textbox2.text)
Pretty simple code that has always worked. I changed a few properties on my ListView as well, and I will list them. I just don't know what is going on.Here's a list of the properties changed (everything else is default):
Properties:
BackColor = DarkGray
BorderStyle = FixedSingle
HeaderStyle = None
MultiSelect = False
View = Details
All properties were changed via the properties tab and not through code. I want to be able to add text to the control. I'm not adding any subitems either. I'm just confused because this code has always worked, and I've never had this issue. I'm also using Visual Basic 2010 Express Edition if that helps.
If the added item in ListView is not displaying then check the ListView.View property. if this property has set to Detail view then Columns must be added in that listView control otherwise added item will not display.
Make sure item is added correctly.
Dim item As ListViewItem = listView1.Items.Add("Item Text") ' This text will be displayed in first column. The column index will be 0
' Further values will be added in SubItem
item.SubItems.Add("Sub Item1")
item.SubItems.Add("Sub Item2")
item.SubItems.Add("Sub Item3")

Set Email Flag Status in Outlook 2007

Is there a way in Outlook 2007 to set a follow-up flag on an email object? It looks like it was supported in Outlook 2003 with .FlagStatus property, but I can't find it in 2007.
From the outlook change notes:
For Follow Up Flags For Follow Up Flags, introduced in Microsoft Office Outlook 2003, are replaced by task flags and color categories. You no longer see colored flags in the Mail view. If you flagged items in the earlier version of Outlook to indicate that they were important or that they belonged to a particular group, you should now use color categories instead. If you used flags to indicate the time at which you were to take action on an item, you should now use task flags. This change is being made to increase the functionality of flags. With task flagging, you can place an item in the overall task management system, allowing you to see your tasks in the To-Do Bar, Daily Task List in Calendar, and in the Tasks view. By categorizing an item, you can easily scan your Inbox for categorized items, the same way that you might previously have scanned your Inbox for flagged items. You can also find categorized items in the Categorized Mail Search Folders.
So the concept of the flag changed, which is why the FlagStatus property has changed. According to this, the following should work:
Set SelectedItems = Outlook.ActiveExplorer.Selection
For Each Item In SelectedItems
With Item
.ToDoTaskOrdinal = dtTaskDate
.TaskDueDate = dtTaskDate
.TaskStartDate = dtTaskDate
.FlagStatus = 2
.FlagRequest = strFlagRequest
.Categories = strCategories
.FlagIcon = 6
.Save
End With
Next Item
This is what http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._mailitem.flagstatus.aspx has to say:
Dim instance As _MailItem
Dim value As OlFlagStatus
value = instance.FlagStatus
instance.FlagStatus = value