I have been searching the internet for hours to find a solution to my question.
I know how to import mails for a long time, but can't keep the format of the HTML-body like I could do when copy the body from OL by hand into the Rich-text memo field on an access form.
The field (olbody) is bound to a SQL server table field olbody (nvarchar(max)) and could store html mail body text when I insert the content of the clipboard.
I even tried to read the .HTMLbody property in the clipboard
clp.SetText .HTMLBody
clp.PutInClipboard
and then I pasted manually the content of the clipboard with Ctrl+V in the field, but again, it does no show up like the HTML mail. But I can see all HTML commands, which should format the mail.
Without formating the mail in the access field, the content is almost unreadable because no tab, lineskip etc. is in the body.
Any help welcome.
Thanks
The proper way to display HTML is using a web browser. This means: use the web browser control!
You can load the HTML in the webbrowser control on load, and when your mail field changes.
Example code:
Private Sub Form_Current()
Dim wb As Object
Set wb = MyWebbrowserControl.Object
With wb
.Navigate2 "about:blank"
Do Until .ReadyState = 4 '=READYSTATE_COMPLETE
'This is a somewhat inefficient way to wait, but loading a blank page should only take a couple of milliseconds
DoEvents
Loop
.Document.Open
.Document.Write MemoField.Value
.Document.Close
End With
End Sub
Replace Memofield with your mail field, and MyWebbroserControl with your webbrowser control, and you should be ready to go.
Note that you probably should use the Access web browser, and not the ActiveX web browser. This code will work with both, but the Access web browser control uses a more modern version of IE, and doesn't come with a non-removable border.
Related
I am scraping data from a proprietary system that serves inventory information via HTML. It includes images of parts that I'd like to scrape, but I cannot use the src link directly (the system is designed to block requests that aren't part of a returned web search). Since I am already scraping the HTML/page text, I'm hoping that someone can tell me how images are stored in IE once a page is loaded, and if there is any way to access that using the MS HTML reference commands/library
I've tried pinging the server directly with various versions of the src URL, with no luck.
Here are some relevant lines of my VBA:
Dim IE As InternetExplorer
Set IE = objShell.Windows(x)
Dim html As Object
Set html = IE.document
Dim ResultClasses as Object
Set resultClasses = html.getElementsByClassName("PM Parts List")
My goal is to add the appropriate IE/HTML call to get the images that were loaded when the page was originally loaded in IE. I cannot call the page to load it from the start within Excel VBA, due to the way items are selected (the load of building out a whole interface within Excel and using sendkeys would be way more hassle than getting the pictures to add to the procurement form for use when validating order reciept
I'm trying to call an outlook procedure from VBScript.
Bellow is my VBScript code (its not working)
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.run "Call_outlook_macro"
objOutlook.Quit
Set objOutlook = Nothing
Please help me.
EDIT:
Basically, I wanted to call outlook macro by clicking a hyper link (using HTML tags and href, I'm not very good with HTML) in incoming mail(this will be sent from servers). But I couldn't find a way to use hyperlinks to call macros.
The work around to this was to create a VBScript to call the outlook macro. I can easily fire a VBscript using a hyper link.
Also, the outlook macro I'm trying to call eventually opens up an outlook form.
If there's a way I can fire outlook macro using hyperlink in the mails, that would be great.
Try
objOutlook.mySub()
instead of objOutlook.Run "Call_outlook_macro" like suggested here.
mySubhas to be in ThisOutlookSession module.
What is your Outlook version? This will not work with all versions how-to-call-vba-macro-from-vbscript-in-outlook-2010.
If you can't call a procedure, you can adapt the sub to VBScript and use it directly, instead of calling it from Outlook.
Alternative: write an Add-In like suggested here handle-hyperlink-click-event-in-outlook-mail.
Alternative 2: Open form with javascript as suggested here To launch a custom Outlook form from a Web page.
There is no way to call a VBA macro from message bodies (hyperlinks). A new Outlook form is shown because you create a new Outlook Application instance:
Set objOutlook = CreateObject("Outlook.Application")
Try to use the GetObject or GetActiveObject functions instead, see GetObject or GetActiveObject cannot find a running Office application for more information.
I'm trying to read messages sent by strangers on Omegle. A random "chat with strangers" website.
I've displayed the DocumentText of my webbrowser (called Omegle) in a textbox called OmegleHTML:
Private Sub Omegle_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles Omegle.DocumentCompleted
OmegleHTML.Text = Omegle.DocumentText
Me.Text = Omegle.Document.Title
End Sub
I've also did a bit of coloring to make things a bit clear:
Now using this HTML code, I've been able to do simple tasks I need such as simulating clicks. But what I'm mainly interested in like I said is extracting the string a stranger says from the HTML code, sadly I'm unable to find what I need in the HTML code I've exported to the textbox, however when I inspect the message element in Chrome:
This is the exact code I need to display in my textbox in order to extract the logitem message a stranger types, now what am I doing wrong? I noticed that when I press Ctrl + U (page source) in chrome, it displays the same exact code my textbox displays, aslo missing the logitems I need, so if I'm not looking for the page source, what should I look for?
The content is written out dynamically using JavaScript. So it isn't part of the page source itself, but is part of the "state" of the page.
See this answer for some details.
How to get rendered html (processed by Javascript) in WebBrowser control?
I was searching for a method to change Outlook Emails to HTML. I found one method that uses VBscript, but it only changes the Outlook File to Text.
Edit: I'm looking for a way to automatically save hundreds of emails to HTML format.
There are number of ways to go here:
Set up a rule to run a script
Wire up a VBS script to fire when you receive and email
Write and Add-in to do the above.
The advantage of the Add-in is that it can be easily deployed compared to rules and scripts, but it a little more complicated.
Number 1 Is probably the easiest to set up if you have no experience.
Open the Visual Basic Editor (Alt+F11) or off the tools menu > Macro
Click on the ThisOutlookSession node on the left
Copt this code in to the right hand page
Sub CustomMailMessageRule(Item As Outlook.MailItem)
Dim HtmlMessagePath As String
HtmlMessagePath = "C:\Users\Marcus\AppData\Roaming\KnowledgeMill\html\" + Item.Subject + ".html"
Call Item.SaveAs(HtmlMessagePath, OlSaveAsType.olHTML)
End Sub
4 .Change the paths and may be use the Item.EntryID as the file name as you could get filename problems with subject you may also want to use mhtml so that you get everything in one file.
5.Create a Rule using the rules wizard and get it to fire on new emails and then to run a script. Click on the Blue script links and select the new script.
6.You may have to adjust you macro security to allow the script to run. (N.B restart outlook after you do this)
You can acutally view the email in a browser in outlook 2007. The option is under under 'other actions' in the ribbon.
You can save the email as html too!
You can set up rules to print emails automatically. I would just set up an HTML printer on your computer.
I'm using Aspose.Cells to build an Excel document programmatically. This works great. One of the cells, though, is a block of raw HTML. I'm wondering if it is possible to tell Excel (in any fashion, including the GUI - you don't need to know the Aspose API) to parse and display a cell as HTML. Right now, it just shows up as the raw HTML in text format, tags and all.
I know Excel is capable of having HTML pasted into it, but it looks like it just parses it on its own and then Excel-ifies it for you, and it doesn't store the HTML, so it's not actually parsing it and displaying it as HTML. Plus, I can't figure out how to replicate this paste functionality anyway.
Thanks.
Unfortunately the answer is no.
Excel has two HTML options:
Open a HTML file, which will sort of render the HTML, sort of, but won't contain any actual HTML in cells
Store HTML in cells, but as unformatted text.
You could, maybe possibly, come up with a macro that lets you enter HTML into a cell, then saves that HTML as a document, opens it up in another instance of Excel, then grabs that formatted HTML and places it in the original document; that way you would have two columns, one with the HTML, and one with the output. It would be very unsightly though. Don't do it :0)
Pasting html data in excel will result in the html being properly displayed in excel. The one issue with this is that carriage returns and tabs will be pasted to the next cell.
Dim objData As New DataObject
objData.SetText(sHTML)
Clipboard.SetDataObject(objData)
objRange.PasteSpecial()
Will fill a cell with properly formated text
This code worked for me on one cell (inspired by #Rick's answer, but with few changes because Clipboard.SetDataObject(objData) caused error and also objRange.PasteSpecial() didn't work):
Private Sub Worksheet_Change2(ByVal Target As Range, ByVal sht As Worksheet)
Dim objData As DataObject 'Set a reference to MS Forms 2.0'
Dim sHTML As String
Dim sSelAdd As String
Application.EnableEvents = False
objData = New DataObject
sHTML = Target.Text
objData.SetText sHTML
objData.PutInClipboard
sht.PasteSpecial Format:="Unicode Text"
Application.EnableEvents = True
End Sub
Sub test()
Dim rng As Range
Set rng = ActiveSheet.Range("F15") 'cell to change'
Worksheet_Change2 rng, ActiveSheet
End Sub
see this post for some more details
I guess it shouldn't be too difficult to tweak it a bit that it would work for entire worksheet and not only one specific cell, you should probably add some if condition to wrap this code in order to prevent errors, see this post for some more info
I found an interesting YouTube video which shows how to create a simple HTML Interpreter (VBA) in Microsoft Excel using the web browser control. Enter your HTML and CSS code into a text box, and the form will convert the HTML into a web preview.
HTML Interpreter in Microsoft Excel 2010/2007 - Write directly to Web Browser