Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy table column from multiple word files into excel

I have hundreds of word files in a folder. Each file contains a table with
two columns. I want to copy the right most column from each word file into 1
excel worksheet, but opening each word file individually and copy/pasting
will take me forever. Does anyone have code the will open each file in the
folder, copy the column and past it into the next available column in an
excel worksheet?

Thanks,
Ml

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Copy table column from multiple word files into excel

This should do it. Make sure M/soft Word Object Library is ticked in Tools,
References in VB Editor and that your active sheet is the one you want them
pasted in (it'll all go wrong after col IV if you've more than 256 docs!):
Sub CopyColumns()
Dim fs As FileSearch
Dim i As Long
Dim myWord As New Word.Application
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.SearchSubFolders = False
.Filename = "*.doc"
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
myWord.Documents.Open .FoundFiles(i)
myWord.ActiveDocument.Tables(1).Columns(2).Select
myWord.Selection.Copy
ActiveSheet.Range("A1").Select
Selection.CurrentRegion.Select
Selection.Offset(0, Selection.Columns.Count).Select
Selection.Resize(1, 1).Select
ActiveSheet.Paste
myWord.ActiveDocument.Close
Next
End If
End With
Set myWord = Nothing
End Sub


"ml_thompson" wrote:

I have hundreds of word files in a folder. Each file contains a table with
two columns. I want to copy the right most column from each word file into 1
excel worksheet, but opening each word file individually and copy/pasting
will take me forever. Does anyone have code the will open each file in the
folder, copy the column and past it into the next available column in an
excel worksheet?

Thanks,
Ml

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy table column from multiple word files into excel

Thanks a million! It worked perfectly! You just saved me hours of work!!!

"Smallweed" wrote:

This should do it. Make sure M/soft Word Object Library is ticked in Tools,
References in VB Editor and that your active sheet is the one you want them
pasted in (it'll all go wrong after col IV if you've more than 256 docs!):
Sub CopyColumns()
Dim fs As FileSearch
Dim i As Long
Dim myWord As New Word.Application
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.SearchSubFolders = False
.Filename = "*.doc"
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
myWord.Documents.Open .FoundFiles(i)
myWord.ActiveDocument.Tables(1).Columns(2).Select
myWord.Selection.Copy
ActiveSheet.Range("A1").Select
Selection.CurrentRegion.Select
Selection.Offset(0, Selection.Columns.Count).Select
Selection.Resize(1, 1).Select
ActiveSheet.Paste
myWord.ActiveDocument.Close
Next
End If
End With
Set myWord = Nothing
End Sub


"ml_thompson" wrote:

I have hundreds of word files in a folder. Each file contains a table with
two columns. I want to copy the right most column from each word file into 1
excel worksheet, but opening each word file individually and copy/pasting
will take me forever. Does anyone have code the will open each file in the
folder, copy the column and past it into the next available column in an
excel worksheet?

Thanks,
Ml

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I copy a word table into excel KF New Users to Excel 2 November 13th 08 03:46 AM
Pivot Table Column Label: Multiple color font on selected word? Pierre Excel Worksheet Functions 3 June 5th 08 05:26 PM
Copy table from Word Document to Excel Mythili Excel Discussion (Misc queries) 0 May 3rd 07 10:50 AM
How do I copy a table from Excel to Word or a chart to Ppt in a ma Linda Vincent Excel Programming 0 November 30th 05 06:00 PM
Copy Word table to Excel Nelson[_3_] Excel Programming 0 July 21st 03 06:54 PM


All times are GMT +1. The time now is 07:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"