Results 1 to 12 of 12
  1. #1
    New Lounger
    Join Date
    Sep 2003
    Location
    Newport, Rhode Island, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert web page content (2002/SP3)

    I'm creating a Word template with a header/footer and I want the body of the document to be the contents of a web page. How can I automate insertion of the web page contents into Word without the user having to save it to a file? Ideally I would like to simply Insert | File ... (specify URL) but Insert File doesn't accept URLs. Can I automate IE from within Word or is there a better way?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Insert web page content (2002/SP3)

    In the past, I've used a couple of different methods.

    File>Open (Documents.Open) does accept a URL. You can open into a separate window, cut the content, close that window, then paste into the main window. Now that I think about it, I was opening as text (source code); I'm not sure how the appearance of the web page might be affected by cutting and pasting. Worth an experiment or two.

    Yes, you can automate IE using VBA. However, I'm not sure it would be that convenient to transfer the page after opening it in IE. In my previous experiences, I was reading out and writing back selected form fields, not trying to replicate the web page in Word...

  3. #3
    New Lounger
    Join Date
    Sep 2003
    Location
    Newport, Rhode Island, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert web page content (2002/SP3)

    That's the general idea except that my source is a .aspx page for which I have edit rights, and Word appears to be importing the page source rather than the delivered content! Annoying, really. What I thought I might do is write a javascript to grab the content out of the url and spit it into Word, but this wouldn't be the forum to ask about that, would it?

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Insert web page content (2002/SP3)

    Word should not import source if you access an http://host/page.aspx address. The web server should not serve source.

  5. #5
    New Lounger
    Join Date
    Sep 2003
    Location
    Newport, Rhode Island, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert web page content (2002/SP3)

    I agree that it shouldn't serve source, but what I see in Word is the blank page template with no content filled in.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Insert web page content (2002/SP3)

    I see, that's different. By "source" I was referring to the VBScript that creates the page layout. Perhaps the problem is that the page is not receiving all of the parameters it needs to fill itself out? If you wrote the ASP pages, you know whether the parameters are gathered from the URL itself (QueryString) or from the body of a form, or in some other manner (e.g., cookies). If someone else wrote the page, and adding parameters to the URL doesn't work, perhaps you will have to automate Internet Explorer after all.

    Added: I was thinking of ASP when I wrote "VBScript." I haven't worked at all with ASP.NET, so perhaps it is a question for the Web Development or .NET boards how to get the full content served into Word.

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Insert web page content (2002/SP3)

    The following is some very simple code along the lines of Jefferson's suggestion - would this work to grab the content of the page?

    Gary

    <pre>Sub OpenFileFromURL()

    Dim WebDoc As Document
    Dim TextDoc As Document

    Set WebDoc = _
    Documents.Open(FileName:="http://www.google.com/", ConfirmConversions:=False, Visible:=False)

    WebDoc.Range.Copy

    WebDoc.Close wdDoNotSaveChanges

    Set TextDoc = _
    Documents.Add

    Selection.Range.PasteSpecial DataType:=wdPasteRTF

    MsgBox TextDoc.Tables(1).Cell(1, 1).Range.Text

    Set WebDoc = Nothing
    Set TextDoc = Nothing

    End Sub
    </pre>


  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Insert web page content (2002/SP3)

    Does it help to add the "read only" parameter to the Documents.Open call?

  9. #9
    New Lounger
    Join Date
    Sep 2003
    Location
    Newport, Rhode Island, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert web page content (2002/SP3)

    Tried read-only already, it doesn't change a thing. Microsoft assumes that if you access a FrontPage server from Word then you want to edit the content, even if it's ASPX. Of course I expect that it wouldn't attempt to save changes back to the server in that case.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Insert web page content (2002/SP3)

    Presumably there's some way to force "anonymous" access to the server, but I've never tried it. If you can get a second username with limited privileges on the server, maybe it can be done by starting word with "RUN AS" set to the less privileged user?

  11. #11
    New Lounger
    Join Date
    Sep 2003
    Location
    Newport, Rhode Island, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert web page content (2002/SP3)

    Gary:

    That code looks a lot like what I've been trying. I think it would work if I didn't have author rights on the server. I've confirmed that what Word is doing is opening the page for FrontPage authoring. What it SHOULD do is a simple GET request on the @!#$%@!# page.

    Of course the end-user the macro is being written for won't get this problem, but what they apparently _will_ get is a series of bogus logon prompts. I've just used a test account to confirm that the Gary's code works just fine as long as the account being used doesn't have authoring rights on the server. Instead I get prompted for logins several times as it tries to author the page.

    [see attached IIS log file entries]

    Still, thanks for the code! I'll see if I can work around my problem by removing server extensions on this web.
    Attached Files Attached Files

  12. #12
    New Lounger
    Join Date
    Sep 2003
    Location
    Newport, Rhode Island, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert web page content (2002/SP3)

    My earlier post with the test account did just that. Specifically I accessed the server using an account that was allowed to retrieve the aspx page but wasn't allowed to author it. Word still went through the motions of trying to open the file for authoring (that's the set of POST actions to author.dll with status 200: IIS says "yes, you can talk to author.dll" then author.dll says "no you can't edit this page" then Word displays another username/password dialog, after the third attempt Word finally gives up and does a GET request to fetch the page content.)

    I have another user with a similar issue in that she uses FrontPage to maintain a subweb but doesn't have rights on the root web; she gets very confused when FrontPage repeatedly prompts for username/password as it tries to open the parent web for authoring.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •