PC Review


Reply
Thread Tools Rate Thread

Display HTML email in Internet Explorer (1 click work around for2007)

 
 
Ken
Guest
Posts: n/a
 
      20th Feb 2008
The VBA code below can be used to open HTML emails in Internet
Explorer. It is essentially the same as opening the Email, Click
Other Actions, View in Browser. I got a start from the code posted on
http://www.howto-outlook.com/howto/openinbrowser.htm This was a quick
and dirty because I needed something quick. We use a web based
calendar and we needed the buttons in emails for accepting meetings to
work. This accomplished that. I have done very little testing on
it. Any improvements are welcome. Hope it helps.


1. Click Alt F11 to open the Visual Basic Editor

2. Expand Project1
3. Expand Microsoft Office Outlook
4. Double Click ThisOutlookSession

5. Paste the following code in the window on the right

--------------------------------------------------------Start
Code-------------------------------------------------------------
Sub OpenInBrowser()

Dim BrowserLocation As String
'Dim Response As Integer

'Set the location of the executable of the browser you want to use
BrowserLocation = "C:\Program Files\Internet Explorer
\iexplore.exe"

'Get the user's TempFolder to store the item in
Dim FSO As Object, TmpFolder As Object
Set FSO = CreateObject("scripting.filesystemobject")
Set FileName = FSO.GetSpecialFolder(2)


'Get all selected items
Dim MyOlNamespace As Outlook.NameSpace
Set MyOlNamespace = Application.GetNamespace("MAPI")
Set myolselection = Application.ActiveExplorer.Selection

'Make sure at least one item is selected
If myolselection.Count = 0 Then
Response = MsgBox("Please select an item first", vbExclamation,
MyApplName)
Exit Sub
End If

'Make sure only one item is selected
If myolselection.Count > 1 Then
Response = MsgBox("Please select only one item", vbExclamation,
MyApplName)
Exit Sub
End If

Dim MySelectedItem As MailItem
Dim sHTML As String
'Retrieve the selected item
Set MySelectedItem = myolselection.Item(1)


sHTML = MySelectedItem.HTMLBody


'save the selected item as htm to the temp folder
Dim sFolderName As String
Dim SaveFile As Object

strname = "www_howto-outlook_com"
FileName = FileName & "\" & strname & ".htm"
sFolderName = FSO.GetTempName
If FSO.fileexists(FileName) Then
Set SaveFile = FSO.OpenTextFile(FileName, 2, False)
Else
Set SaveFile = FSO.OpenTextFile(FileName, 2, True)
End If

SaveFile.Write sHTML
SaveFile.Close



'open the saved item in the browser
Shell BrowserLocation & " " & FileName, vbNormalFocus

'Cleanup
Set FSO = Nothing
Set FileName = Nothing
Set MyOlNamespace = Nothing
Set myolselection = Nothing
Set MySelectedItem = Nothing

End Sub

-------------------------------------------------------------------------
End Code-----------------------------------------------

6. Add button to the tool bar that runs the macro

 
Reply With Quote
 
 
 
 
Roady [MVP]
Guest
Posts: n/a
 
      20th Feb 2008
Thanks for crediting my solution but why copy the contents of my webpage
into your post?
This is not proper etiquette.

>> I got a start from the code

Why didn't you comment your code changes and motivation for it?

Don't get me wrong; you can freely use and modify the code provided on my
webpage but when you are going to repost it publicly, there are better and
more proper ways to do so. Not properly separating the reference and your
own contribution is considered plagiarism.

--
Robert Sparnaaij [MVP-Outlook]
Coauthor, Configuring Microsoft Outlook 2003
http://www.howto-outlook.com/
Outlook FAQ, HowTo, Downloads, Add-Ins and more

http://www.msoutlook.info/
Real World Questions, Real World Answers

-----

"Ken" <(E-Mail Removed)> wrote in message
news:dd314e5d-d0bd-4b1b-86dc-(E-Mail Removed)...
> The VBA code below can be used to open HTML emails in Internet
> Explorer. It is essentially the same as opening the Email, Click
> Other Actions, View in Browser. I got a start from the code posted on
> http://www.howto-outlook.com/howto/openinbrowser.htm This was a quick
> and dirty because I needed something quick. We use a web based
> calendar and we needed the buttons in emails for accepting meetings to
> work. This accomplished that. I have done very little testing on
> it. Any improvements are welcome. Hope it helps.



 
Reply With Quote
 
Ken
Guest
Posts: n/a
 
      20th Feb 2008

> Don't get me wrong; you can freely use and modify the code provided on my
> webpage but when you are going to repost it publicly, there are better and
> more proper ways to do so. Not properly separating the reference and your
> own contribution is considered plagiarism.
>

I certainly didn't mean to plagiarize (thus the reference to your
original work). Without your original work I wouldn't have figured
out the solution to my problem. I spent a few hours last night
searching and your website was the only thing even close. Telling
users to open the mail, click other actions, and then select view in
browser was a non-starter. Your code opened the email in IE but
apparently used Word Formatting because the buttons were still not
active.
Do you have a reference for how to properly quote original
code?? I'm searching the etiquette posts but haven't seen anything.
The slightly cleaned up code(hopefully, correctly annotated) is
below. I apologize.


Sub OpenInBrowser()
'This procedure was written by Robert Spaarnaaij
'and may be found at http://www.howto-outlook.com/openinbrowser.htm
'Several lines have been added to save the html from the email.
'The original used file saveas

Dim BrowserLocation As String
'Dim Response As Integer

'Set the location of the executable of the browser you want to use
BrowserLocation = "C:\Program Files\Internet Explorer
\iexplore.exe"

'Get the user's TempFolder to store the item in
Dim FSO As Object, TmpFolder As Object
Set FSO = CreateObject("scripting.filesystemobject")
Set FileName = FSO.GetSpecialFolder(2)


'Get all selected items
Dim MyOlNamespace As Outlook.NameSpace
Set MyOlNamespace = Application.GetNamespace("MAPI")
Set MyOlselection = Application.ActiveExplorer.Selection

'Make sure at least one item is selected
If MyOlselection.Count = 0 Then
Response = MsgBox("Please select an item first", vbExclamation,
MyApplName)
Exit Sub
End If

'Make sure only one item is selected
If MyOlselection.Count > 1 Then
Response = MsgBox("Please select only one item", vbExclamation,
MyApplName)
Exit Sub
End If

Dim MySelectedItem As MailItem 'added declaration to make MySelected
Item a MailItem object

'Retrieve the selected item
Set MySelectedItem = MyOlselection.item(1)


Dim sHTML As String 'Added string variable to hold the HTMLBody
'apparently the original code saved the file in Word Format

sHTML = MySelectedItem.HTMLBody 'Added to place the HTML from the
email into the temp file


'save the selected item as htm to the temp folder
strname = "www_howto-outlook_com"
FileName = FileName & "\" & strname & ".htm"
'The following line was in the original code - it was replaced
with code for saving
'the HTML
MySelectedItem.SaveAs FileName, olHTML

Dim SaveFile As Object 'added for use in saving the HTML file

'Added next 7 lines to write and save the HTML file
If FSO.fileexists(FileName) Then
Set SaveFile = FSO.OpenTextFile(FileName, 2, False)
Else
Set SaveFile = FSO.OpenTextFile(FileName, 2, True)
End If

SaveFile.Write sHTML
SaveFile.Close

'open the saved item in the browser
Shell BrowserLocation & " " & FileName, vbNormalFocus

'Cleanup
Set FSO = Nothing
Set FileName = Nothing
Set MyOlNamespace = Nothing
Set MyOlselection = Nothing
Set MySelectedItem = Nothing
Set SaveFile = Nothing 'Added

End Sub
 
Reply With Quote
 
Roady [MVP]
Guest
Posts: n/a
 
      20th Feb 2008
Hi Ken,

No, it's good this way, no problem. I saw your reference intention so I
kinda figured already you didn't do it on purpose. I'm in a research
environment where not properly referencing is enough to lose your titles so
I can be overly jumpy on that sometimes ;-)

Could you send me an example of what exactly you are trying to fix? It's
kind of vague to me what is not working for you in plain vanilla Outlook
2007 and what you are trying to solve with my macro and to what extend it
requires modification. Maybe we can work together on some code modifications
that can benefit the masses. You'll find a contact link on my website.

--
Robert Sparnaaij [MVP-Outlook]
Coauthor, Configuring Microsoft Outlook 2003
http://www.howto-outlook.com/
Outlook FAQ, HowTo, Downloads, Add-Ins and more

http://www.msoutlook.info/
Real World Questions, Real World Answers

-----

"Ken" <(E-Mail Removed)> wrote in message
news:e2432853-b858-47ce-955d-(E-Mail Removed)...
>
>> Don't get me wrong; you can freely use and modify the code provided on my
>> webpage but when you are going to repost it publicly, there are better
>> and
>> more proper ways to do so. Not properly separating the reference and your
>> own contribution is considered plagiarism.
>>

> I certainly didn't mean to plagiarize (thus the reference to your
> original work). Without your original work I wouldn't have figured
> out the solution to my problem. I spent a few hours last night
> searching and your website was the only thing even close. Telling
> users to open the mail, click other actions, and then select view in
> browser was a non-starter. Your code opened the email in IE but
> apparently used Word Formatting because the buttons were still not
> active.
> Do you have a reference for how to properly quote original
> code?? I'm searching the etiquette posts but haven't seen anything.
> The slightly cleaned up code(hopefully, correctly annotated) is
> below. I apologize.
>
>
> Sub OpenInBrowser()
> 'This procedure was written by Robert Spaarnaaij
> 'and may be found at http://www.howto-outlook.com/openinbrowser.htm
> 'Several lines have been added to save the html from the email.
> 'The original used file saveas
>
> Dim BrowserLocation As String
> 'Dim Response As Integer
>
> 'Set the location of the executable of the browser you want to use
> BrowserLocation = "C:\Program Files\Internet Explorer
> \iexplore.exe"
>
> 'Get the user's TempFolder to store the item in
> Dim FSO As Object, TmpFolder As Object
> Set FSO = CreateObject("scripting.filesystemobject")
> Set FileName = FSO.GetSpecialFolder(2)
>
>
> 'Get all selected items
> Dim MyOlNamespace As Outlook.NameSpace
> Set MyOlNamespace = Application.GetNamespace("MAPI")
> Set MyOlselection = Application.ActiveExplorer.Selection
>
> 'Make sure at least one item is selected
> If MyOlselection.Count = 0 Then
> Response = MsgBox("Please select an item first", vbExclamation,
> MyApplName)
> Exit Sub
> End If
>
> 'Make sure only one item is selected
> If MyOlselection.Count > 1 Then
> Response = MsgBox("Please select only one item", vbExclamation,
> MyApplName)
> Exit Sub
> End If
>
> Dim MySelectedItem As MailItem 'added declaration to make MySelected
> Item a MailItem object
>
> 'Retrieve the selected item
> Set MySelectedItem = MyOlselection.item(1)
>
>
> Dim sHTML As String 'Added string variable to hold the HTMLBody
> 'apparently the original code saved the file in Word Format
>
> sHTML = MySelectedItem.HTMLBody 'Added to place the HTML from the
> email into the temp file
>
>
> 'save the selected item as htm to the temp folder
> strname = "www_howto-outlook_com"
> FileName = FileName & "\" & strname & ".htm"
> 'The following line was in the original code - it was replaced
> with code for saving
> 'the HTML
> MySelectedItem.SaveAs FileName, olHTML
>
> Dim SaveFile As Object 'added for use in saving the HTML file
>
> 'Added next 7 lines to write and save the HTML file
> If FSO.fileexists(FileName) Then
> Set SaveFile = FSO.OpenTextFile(FileName, 2, False)
> Else
> Set SaveFile = FSO.OpenTextFile(FileName, 2, True)
> End If
>
> SaveFile.Write sHTML
> SaveFile.Close
>
> 'open the saved item in the browser
> Shell BrowserLocation & " " & FileName, vbNormalFocus
>
> 'Cleanup
> Set FSO = Nothing
> Set FileName = Nothing
> Set MyOlNamespace = Nothing
> Set MyOlselection = Nothing
> Set MySelectedItem = Nothing
> Set SaveFile = Nothing 'Added
>
> End Sub


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Click email link opens 60+ copies of Internet Explorer? =?Utf-8?B?U21hcnRBbGVja1RleGFu?= Windows XP Internet Explorer 3 25th Mar 2006 05:11 AM
HTML Navigation Bar Buttons - some display that don't work =?Utf-8?B?TGluZGE=?= Microsoft Access VBA Modules 0 31st Mar 2005 10:09 PM
Internet Explorer problem: does not display html pages breeze Windows XP General 8 16th Nov 2004 03:12 PM
Re: Right-Click dosn't work in Internet explorer Ramesh [MVP] Windows XP Help 0 21st Aug 2004 05:16 AM
Internet Explorer Script Error when printing HTML email Joe Microsoft Outlook 0 22nd Aug 2003 03:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:34 PM.