+ Reply to Thread
Results 1 to 2 of 2

How to select the first 5 paragraphs in a Word Document from Excel

  1. #1
    quartz
    Guest

    How to select the first 5 paragraphs in a Word Document from Excel

    Does anyone know how to select the first 5 paragraphs in a Word document from
    Excel?

    I can get a ref and open the document. Now I need to select the first 5
    paragraphs and copy them to the clipboard. My code so far looks like this:

    Dim wdApp As Word.Application
    Set wdApp = New Word.Application
    wdApp.Documents.Open Filename:=argFullName, ReadOnly:=argReadOnly
    <<<code to select first 5 paragraphs needed here>>>
    <<<code to copy needed here>>
    wdApp.Documents(FileName).Close SaveChanges:=False
    wdApp.Application.Quit
    Set wdApp = Nothing

    Thanks in advance.

  2. #2
    JulieD
    Guest

    Re: How to select the first 5 paragraphs in a Word Document from Excel

    Hi

    this seems to work

    Sub testword()
    Dim wdApp As Word.Application
    Set wdApp = New Word.Application
    argFullname = "C:\test.doc"
    wdApp.documents.Open Filename:=argFullname, ReadOnly:=argReadOnly
    wdApp.Selection.HomeKey Unit:=wdStory
    wdApp.Selection.MoveDown Unit:=wdParagraph, Count:=5, Extend:=wdExtend
    wdApp.Selection.Copy
    wdApp.documents(argFullname).Close SaveChanges:=False
    wdApp.Application.Quit
    Set wdApp = Nothing

    ThisWorkbook.Activate
    Sheets("Sheet4").Activate
    Range("A1").Select
    ActiveSheet.Paste
    Msgbox "Done"
    End Sub


    Hope this helps
    Cheers
    JulieD

    "quartz" <[email protected]> wrote in message
    news:[email protected]...
    > Does anyone know how to select the first 5 paragraphs in a Word document
    > from
    > Excel?
    >
    > I can get a ref and open the document. Now I need to select the first 5
    > paragraphs and copy them to the clipboard. My code so far looks like this:
    >
    > Dim wdApp As Word.Application
    > Set wdApp = New Word.Application
    > wdApp.Documents.Open Filename:=argFullName, ReadOnly:=argReadOnly
    > <<<code to select first 5 paragraphs needed here>>>
    > <<<code to copy needed here>>
    > wdApp.Documents(FileName).Close SaveChanges:=False
    > wdApp.Application.Quit
    > Set wdApp = Nothing
    >
    > Thanks in advance.




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1