I need to rollout an Outlook VBA macro to disable and display all hyperlinks in email messages.
Optimally all hyperlinks would be disabled from being clickable and for text that have a “hidden” link the link would be disabled and following the text (still in blue) the link would be displayed within square brackets.
I have a lot of Excel VBA experience but almost no Outlook VBA experience. I’m surprised this code isn’t all over the place but after a week of searching I’ve found nothing.
You would need to retrieve the HTML body (MailItem.HTMLBody property), load it into an instance of the IHTMLDocument2 object, loop thorough the links collection and modify the links. You will then need to retrieve the modified HTML body and set the MailItem.HTMLBody property.
You can of course do your own parsing by looking at all the <a> tags in the HTML body instead of using the IHTMLDocument2 object.
Related
In a Word template I have a command button with VBA code behind it.
The problem is that the code gets lost when a document is created using that template. The button is still visible, but the VBA code behind it disappears for some reason. This causes the button just to be clickable without performing any action.
The documents are saved in .docx format.
How can I 'glue' the button to its code so it doesn't get lost ?
First, make sure your VBA code is saved in the .dotm template that you make available to everyone (and not in your personal normal.dot/dotm template — this is only available on your machine).
Then, make sure the documents generated from the template are saved as .docm (not .docx).
.docx documents cannot contain VBA code. Anything saved in .dotx or .docx format will, by definition, lose all VBA code.
In a comment you say
"this doenst matter, as the document is just used for the macro."
This is incorrect; it does very much matter. .docx documents can't "be used for" macros because they can't contain macros.
For the macro to be always available, you need to store the macro in the normal template.
For example when recording a macro, select All Documents (Normal.dot) on Store Macro in.
How do I set the font of selected text in Outlook's HTML editor? I found a couple of answers on google, but none of them worked.
What version of Outlook are you using? In case of Outlook 2010 and up, Outlook always uses the Word editor and you can access it Application.ActiveExplorer.WordEditor, which returns an instance of the Word's Document object. Once you have it, you can use the Word object model to change the selected text attributes.
I am working with Microsoft Word 2010. I have a document that serves as a template for multiple users for a project I am working on. There are two parts of the document I want to force formatting when a user types:
Enter in an email address - I want the address to not automatically turn to a hyperlink. I want it to not turn to a hyperlink on just this part of the document. The rest of it I want hyperlinks to be enabled.
Enter in a URL without www in front (i.e. google.com), and not have the first letter automatically capitalize. I don't want to turn off capitalizing the first letter of a sentence in the whole document. Just in this part of the document.
Is this something that can be done? I tried messing with Fields but did not have any luck. I am familiar with VBA so if there is a way to do this with code, I am open to that too.
Both features you requires are implemented in Word using AutoCorrect/AutoFormat. They are not controlled by the style mechanism and consequently can't be selectively activated.
The mail address formatting can be controlled by styles, and you could prevent the switch to the Hyperlink style from being visible. You could also consider a macro that selectively changes the styles of the text as required in a post-processing pass through the documents - perhaps the next time the document is opened by a user for review.
I have a word doc with some ActiveX buttons on it. When one of these buttons is pressed, a UserForm pops up with a corresponding PDF displayed, like so:
This is exactly the behavior I want. However, the problem is that for this to work, the user of the word doc needs to have each of the PDFs saved on their machine as well. Here's the code for one of the buttons:
Private Sub AC1Button_Click()
DisplayForm.AcroPDF1.LoadFile ("C:\Users\arose\Desktop\Security Control Doc\Sub PDFs\AC1.pdf")
DisplayForm.Show
End Sub
As you can see, the path is hardcoded in. I need to be able to distribute this word doc without needing to distribute a bunch of PDFs along with it, so is there any way to embed PDFs in a word document in such a way that they're accessible by VBA?
I've discovered here that it's reasonably easy to embed a PDF in any office doc. And I've tried that:
But I can't figure out how to access that PDF object in my VBA code, in order to display it on the UserForm.
Any insight is appreciated, thanks!
Embed the files (and display as icon to stop them taking over your document)
To activate the first OLE object in your document,
ThisDocument.InlineShapes(1).OLEFormat.Activate
is the command.
I am automating Word from VB.Net.
I open a document by:
Dim msWord as Word.Application = CreateObject("Word.Application")
Dim doc As Word.Document = msWord.Documents.Add(Template:=Path)
where path points to a template file I created with a header and a watermark. The template has some bookmarks which I want to dynamically set to some appropriate text values:
doc.Bookmarks("DocumentTitle").Range.Text = "The Joy of Office Automation"
If I comment out that line, the document opens in Word with the watermark, etc, in place. If I let that line execute, it inserts the text as appropriate, but the watermark and other things disappear from the document. You can actually see it flash briefly, and then disappear.
FWIW, this is Office Word 2007, and I am opening a .Dot (Word 97-2003) template. The Bookmark.Range.Text I am setting is in the document header.
Office Automation gurus, what am I doing wrong?
Thanks,
Gerald
My first thought is maybe somehow you've got the watermark associated with the range that the bookmark "marks". If you then replace that range with some other text, pop! no more watermark.
But that seems like a longshot because I don't think watermarks are normally associated with ranges.
Is it possible the bookmark spans a section break? If the watermark is set to a specific section and replacing the bookmark wipes out the section break, you'll loose everything about that section (including possibly headers, footers, margins etc).
I have discovered some more information: The watermark only disappears if the bookmark in question is in the very first position within the document header. Setting any other bookmark within the document does not cause the watermark to disappear. Adding even a single space before the bookmark in question will prevent the watermark from disappearing when the range text is set.