K
Ken
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
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