Consulting

Results 1 to 4 of 4

Thread: Solved: Copy from Word document and paste into new Excel document

  1. #1

    Solved: Copy from Word document and paste into new Excel document

    I have a MS Word document.

    I am looking for a way to copy all of the contents of the file into a new Excel worksheet/workbook.

    The problem (i think) is that my Visual Basic project is a XLA file. Can i still do this with the same project?

    So, basically:

    Copy all the contents of a MS Word document
    Open a new MS Excel Document
    Paste the content into the Excel Document.

    TIA.

    Picco

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Picco,

    I assume the automation is done from Excel?

    If so I see no reason why you couldn't have a sub in your addin that would perform the action..

    The sub could look something like:[VBA]
    Option Explicit
    Sub WordToNewExcel()
    'Set reference to Microsoft Word (version) object library
    Dim oApp As New Word.Application
    Dim oDoc As Word.Document
    Dim sPath As String
    sPath = ThisWorkbook.Path & Application.PathSeparator & "test.doc"
    Set oDoc = oApp.Documents.Open(Filename:=sPath)

    oDoc.Range.Copy
    oDoc.Close False

    With Application
    .Workbooks.Add
    .ActiveSheet.Paste
    End With

    oApp.Quit False
    Set oDoc = Nothing
    Set oApp = Nothing
    End Sub
    [/VBA]

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #3
    that worked gr8 - thanx

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    You're Welcome!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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