|
-
Aug 16th, 2005, 11:43 AM
#1
Thread Starter
New Member
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!
-
Aug 16th, 2005, 12:28 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 16th, 2005, 01:41 PM
#3
Thread Starter
New Member
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?
-
Aug 16th, 2005, 01:43 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 16th, 2005, 03:57 PM
#5
Thread Starter
New Member
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
-
Aug 16th, 2005, 04:37 PM
#6
Thread Starter
New Member
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.
-
Aug 16th, 2005, 11:39 PM
#7
Re: Copying from Word and pasting into Excel
This line is redundant and not needed.
VB Code:
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 18th, 2005, 11:06 AM
#8
Thread Starter
New Member
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.
-
Aug 19th, 2005, 10:09 AM
#9
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:
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range("A1")
or
VB Code:
Range("A1").PasteSpecial xlPasteAll
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 19th, 2005, 04:18 PM
#10
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|