'Accessing all open excel and outlook emails from Word Macro
I have developed a Word document containing a macro that can transfer all Content Control Values to any other open Word document. I would like to expand on this so it can look through any emails that are open for editing. Is this even possible? My current code relies on SelectContentControlsByTag, but I think this is exclusive to the Word API.
Private Sub DumpData_Click()
Dim updated As Boolean
Dim doc_updated As Integer
Dim msg As String
'Dim content_controls_collection As Collection
msg = ""
Set source_doc = Application.ActiveDocument
'For each open document that is not the active document (the active document is the source file containing the macro button and this script)
For Each destination_doc In Documents
If destination_doc <> source_doc Then
updated = False
'Look at each content control in the destination doc
For Each content_control In destination_doc.ContentControls
'Set content_controls_collection = Nothing
CC_tag = content_control.Tag
'If the tags are not empty
If CC_tag <> "" Then
' msg = msg & vbNewLine & "Found tag " & CC_tag & " in " & destination_doc.Name
'find the corresponding content control, if it exists, in the source document
If source_doc.SelectContentControlsByTag(CC_tag).Count > 0 Then
'If the content control is the basic text type
If content_control.Type = wdContentControlText Or _
content_control.Type = wdContentControlDate Or _
content_control.Type = wdContentControlRichText Then
content_control.Range.Text = source_doc.SelectContentControlsByTag(CC_tag).Item(1).Range.Text
updated = True
' msg = msg & vbNewLine & "Content Control was updated!"
Else
msg = msg & vbNewLine & CC_tag & " tag is a less common type of content control which I have not bothered to progam to transfer. It's type is " & content_control.Type
End If
' Else
' msg = msg & vbNewLine & CC_tag & " tag not found in Project Form Data Source."
End If
End If
Next content_control
If updated = True Then
msg = msg & vbNewLine & " - " & destination_doc.Path & Application.PathSeparator & destination_doc.Name
doc_updated = doc_updated + 1
End If
End If
Next destination_doc
If doc_updated > 0 Then
msg = "Macro complete. The following open documents were found to contain matching Content Controls which are now updated:" & msg
Else
msg = "No open files were found to contain matching Content Control Tags."
End If
MsgBox msg
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
