Solved

Copy & Paste HTML Content

Posted on 2003-12-11
10
954 Views
Last Modified: 2012-06-21
What I want to do is...
Copy HTML content from a web page (via iexplorer) and retrieve the content.
For example if I paste it in a text box I will have the text and not the html, if I paste it in word I will have html content...
Many thx
0
Comment
Question by:meciab
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Assisted Solution

by:bossjohnc
bossjohnc earned 200 total points
ID: 9919498
This will get the contents of an HTML page and put it in to a string...


Option Compare Database

Option Explicit
'Begin declarations for URL opening
'----------------------------------
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3

Private Const scUserAgent = "VB Project"
Private Const INTERNET_FLAG_RELOAD = &H80000000

Private Declare Function InternetOpen Lib "wininet.dll" _
  Alias "InternetOpenA" (ByVal sAgent As String, _
  ByVal lAccessType As Long, ByVal sProxyName As String, _
  ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

Private Declare Function InternetOpenUrl Lib "wininet.dll" _
  Alias "InternetOpenUrlA" (ByVal hOpen As Long, _
  ByVal sUrl As String, ByVal sHeaders As String, _
  ByVal lLength As Long, ByVal lFlags As Long, _
  ByVal lContext As Long) As Long

Private Declare Function InternetReadFile Lib "wininet.dll" _
  (ByVal hFile As Long, ByVal sBuffer As String, _
   ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) _
  As Integer

Private Declare Function InternetCloseHandle _
   Lib "wininet.dll" (ByVal hInet As Long) As Integer
'--------------------------------
'End declarations for URL opening

Public Function OpenURL(ByVal sUrl As String) As String
'****************************************************
'PURPOSE:       Returns Contents (including all HTML) from
'               a web page
'PARAMETER:     sURL (e.g., http://www.freevbcode.com)
'RETURN VALUE:  Contents of requested page, or
'               empty string if sURL is not available
'COMMENTS:  This is an alternative to using the Internet Transfer
'           Control 's OpenURL method.  That control has a bug
'           Whereby not all the contents of the page will be
'           returned in certain circumstances
'*****************************************************

    Dim hOpen               As Long
    Dim hOpenUrl            As Long
    Dim bDoLoop             As Boolean
    Dim bRet                As Boolean
    Dim sReadBuffer         As String * 2048
    Dim lNumberOfBytesRead  As Long
    Dim sBuffer             As String

hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, _
    vbNullString, vbNullString, 0)

hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, _
   INTERNET_FLAG_RELOAD, 0)

    bDoLoop = True
    While bDoLoop
        sReadBuffer = vbNullString
        bRet = InternetReadFile(hOpenUrl, sReadBuffer, _
           Len(sReadBuffer), lNumberOfBytesRead)
        sBuffer = sBuffer & Left$(sReadBuffer, _
             lNumberOfBytesRead)
        If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
    Wend
     
    If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
    If hOpen <> 0 Then InternetCloseHandle (hOpen)
    OpenURL = sBuffer

End Function
0
 
LVL 3

Expert Comment

by:bossjohnc
ID: 9919530
This will chop the front of the string off up until you find a keyword that you want...

You might have to do something similar for the end of the text if you really want it to be neat...

strKey = "my keyword"
strData = OpenURL("http://www.myurl.com/mypage.html")

Do While strData <> ""
KLStart:
    Do While strKey <> ""
        strKeyLet = Mid(strKey, 1, 1)
        If Mid(strData, 1, 1) = strKeyLet Then
            strKey = Mid(strKey, 2)
            strData = Mid(strData, 2)
            If strKey = "" Then
                Me.txtMyText = strData
                Exit Sub
            End If
        Else
            If strData = "" Then
                MsgBox "Key Not Found!"
                Exit Sub
            End If
            strData = Mid(strData, 2)
            GoTo KLStart
        End If
    Loop
Loop
0
 

Author Comment

by:meciab
ID: 9919532
sorry, but that's not what I want to do, I don't want to retrieve a page from an url.
I want to copy a part of a page, (via iexplorer) and retrieve the html content.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 26

Expert Comment

by:Alan Warren
ID: 9919573
You mean like: right click the page and choose view source, then copy/paste.

or File > SaveAs > Webpage Complete

do you want to do this programatically?


Alan :)
0
 
LVL 8

Expert Comment

by:ampapa
ID: 9919622
Why don't you use paste special in Word and paste it as unformatted text?

Do you also need to do this progmatically? Here is a link to MS that will help in getting info from the clipboard -  http://support.microsoft.com/?kbid=212730

Here is also some info on using the clipboard: (http://graphicsmagician.com)

Visual Basic: Using the Clipboard with Text
Methods used with the clipboard:


Clipboard.Clear            'clears the clipboard contents
Clipboard.SetText string      'puts 'string' text on the clipboard
Clipboard.GetText()            'returns clipboard's text as a string
Text1.SelText            'refers to selected text,
                  'or cursor's position in text control
Example
Assume txtBox is a Text Box control:


Sub mnuCut_Click ()
    ' empty the clipboard
    Clipboard.Clear
    ' copy the selected text to the clipboard
    Clipboard.SetText txtBox.SelText
    ' and remove the selected text
    txtBox.SelText = ""
End Sub

Sub mnuCopy_Click ()
    ' empty the clipboard
    Clipboard.Clear
    ' and copy the selected text to the clipboard
    Clipboard.SetText txtBox.SelText
End Sub

Sub mnuPaste_Click ()
    ' paste clipboad text into document
    txtBox.SelText = Clipboard.GetText()
End Sub


0
 

Author Comment

by:meciab
ID: 9920211
just try something
select the bottom of thise page press ctrl+c then got o word and press ctrl+v
You will have the text formatted. How to retrieve this content
Is there an activeX or any object who can handle html in access.
Thanks
0
 

Author Comment

by:meciab
ID: 9920241
Or is a word object can be integreted in access.
where I can paste (from part of html page), write, read data on it and store the content.
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 300 total points
ID: 9920263
yeah a microsoft Web Browser control can handle html in Access

You can embed a Microsoft Web Browser into your form.

Create a new form, show the toolbox, click the more tools icon in the bottom right corner of the toolbox.
Choose Microsoft Web Browser.

This control is capable of running most any website within an Access Form and can be driven using Access VBA.

Me.WebBrowser1.Navigate "someURL"

Alan :)


0
 
LVL 3

Expert Comment

by:bossjohnc
ID: 9920389
If you wanted to store pages, you could get them with the code I posted and then view them with the browser control Alan mentions.
0
 
LVL 3

Expert Comment

by:bossjohnc
ID: 9920393
If you wanted to store pages, you could get them with the code I posted and then view them with the browser control Alan mentions.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question