copy exact content of webpage in word via visual basic

Posted on 2007-09-28
Last Modified: 2010-04-30

I am creating a Visual Basic 6 app that needs to take the content of a webpage (including images, formatting, etc.) and copy it into a Word file.

I thought about two ways of doing this:
1)Open an instance of IE via Visual Basic, do a "Select All - Copy", then paste the clipboard in Word
2)Save the webpage as mht and open it in Word (is there a component that lets me save a url as if I opened Explorer and did "Save As Mht file"?)

Can you guys show me how to accomplish any of these two strategies?

Question by:Vido81
    LVL 23

    Expert Comment

    by:Ashish Patel
    Use WebControls activex using Microsoft Internet controls and then get the data to copy in clipboard and then get to winword.
    LVL 23

    Accepted Solution

    Or use the following to get the output of the webpage by the following. May be this function can be usefull to you.

    Option Explicit

    Public Function GetSource(ByVal Url As String, ByVal TargetFilePath As String) As String
        Dim Obj
        Set Obj = CreateObject("MSXML2.ServerXMLHTTP")
        Dim Status As Variant
        Status = "Nothing"
        Obj.Open "GET", Url
        If Not Obj.Status = 200 Then
            Status = "Error Occurred : " & Obj.Status & " - " & Obj.statusText
            GetSource= "false"
            Open TargetFilePath For Output As #1
            Print #1, Obj.responseText
            Close #1
            Status = "File Created As :" & TargetFilePath
            GetSource= "true"
        End If
        Set Obj = Nothing
    End Function


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now