Results 1 to 10 of 10

Thread: Copying from Word and pasting into Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Copying from Word and pasting into Excel

    I'm trying to create code for excel that will allow me to open a series of word documents, copy certain rows from tables in those docs, and paste them into the excel worksheet.

    I know how to open word from excel, but my knowledge ends there....

    Can someone please help me, by explaining how to open a word doc, copy a table/row, and paste it into excel?

    Thank you!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Copying from Word and pasting into Excel

    Welcome to the Forums.

    Use the Tables collection to access the rows of a table for reading into a variable and then setting a cell in Excel to that var. etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Re: Copying from Word and pasting into Excel

    I think I need to use the copy and paste methods, because setting a cell's value equal to a row from a table in Word does not retain proper formatting of the cells.

    Is there any way to copy specific rows (say from table(1) and table(3)) from word, and paste them onto specific rows in Excel?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Copying from Word and pasting into Excel

    In word you can use Selection and the Windows clipboard to copy and then set the cell value to the clipboard.gettext to "paste it in.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Re: Copying from Word and pasting into Excel

    Using the clipboard is giving me an error, while using range.copy and range.past is pasting the text with odd formatting.

    Here is my code, using clipboard. what is wrong with this?

    Dim oWrd As Object
    Set oWrd = CreateObject("Word.Application")
    Dim oDoc As Object
    Set oDoc = CreateObject("Word.Document")
    Set oDoc = oWrd.Documents.Open("c:\OMA\TIJ.doc")

    oDoc.Tables(1).Rows(1).Range.Select
    Selection.Copy
    ActiveWorkbook.Worksheets(1).Cells(5, 5) = Clipboard.GetText

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Re: Copying from Word and pasting into Excel

    If use this code to copy and paste...

    oDoc.Tables(3).Rows(3).Range.Copy
    ActiveSheet.Paste

    ....it pastes the data properly, but I cannot specify where in the worksheet to paste it.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Copying from Word and pasting into Excel

    This line is redundant and not needed.
    VB Code:
    1. Set oDoc = CreateObject("Word.Document")
    You can set the ActiveCell to the position where you want to paste it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Re: Copying from Word and pasting into Excel

    How can I specify where to paste the rows?

    ActiveSheet.Paste seems to paste it properly, but not in the location I want.

  9. #9
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Copying from Word and pasting into Excel

    You can either specify the destination on the ActiveSheet.Paste or set the range object and pastespecial..

    VB Code:
    1. ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range("A1")

    or

    VB Code:
    1. Range("A1").PasteSpecial xlPasteAll
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  10. #10

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Re: Copying from Word and pasting into Excel

    Thanks,

    I did it like this:
    ActiveWorkbook.Worksheets(1).Cells(aRow, iCol).Value = Application.Clean(.Cell(iRow, iCol).Range)

Posting Permissions

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



Click Here to Expand Forum to Full Width