Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-09-2014, 06:26 AM
spiderman1369 spiderman1369 is offline Loop through files and Copy Table Row and Paste into Different Document Windows 7 64bit Loop through files and Copy Table Row and Paste into Different Document Office 2010 64bit
Novice
Loop through files and Copy Table Row and Paste into Different Document
 
Join Date: Oct 2014
Posts: 2
spiderman1369 is on a distinguished road
Default Loop through files and Copy Table Row and Paste into Different Document

I have a folder with about 300 Word 2010 documents and each has a table in the document. The naming convention for the files is 3-ABC-DE-####.docx (where #### = numbers). I also have a file in the same directory named 3-ABC-FGH-001.docx (this is a table of contents file).



I need to copy the same specific row from the table in each of the 300 documents and sequentially paste each row into the Table of Contents file. Thus having 300 rows in the TOCs file.

Thus, loop through all 300 files, copy the specific row, and dump it into the TOC file.

Is it possible to do this with some vba code? Any sugguestions?
Reply With Quote
  #2  
Old 10-09-2014, 06:07 PM
macropod's Avatar
macropod macropod is offline Loop through files and Copy Table Row and Paste into Different Document Windows 7 64bit Loop through files and Copy Table Row and Paste into Different Document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It's quite easy, really:
Code:
Sub GetData()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String
Dim wdDocSrc As Document, wdDocTgt As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set wdDocTgt = ActiveDocument
strFile = Dir(strFolder & "\3-ABC-DE-*.docx", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> wdDocTgt.FullName Then
    Set wdDocSrc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDocSrc
      If .Tables.Count > 0 Then
        wdDocTgt.Paragraphs.Last.Range.FormattedText = .Tables(1).Rows(1).Range.FormattedText
      End If
      .Close SaveChanges:=False
    End With
  End If
  strFile = Dir()
Wend
Set wdDocSrc = Nothing: Set wdDocTgt = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
All you need do is add the code to your target document and specify which table & row to use. As coded, the macro assumes the first table and the first row in that table.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-15-2014, 08:30 AM
spiderman1369 spiderman1369 is offline Loop through files and Copy Table Row and Paste into Different Document Windows 7 64bit Loop through files and Copy Table Row and Paste into Different Document Office 2010 64bit
Novice
Loop through files and Copy Table Row and Paste into Different Document
 
Join Date: Oct 2014
Posts: 2
spiderman1369 is on a distinguished road
Default

Thanks macropod...just got to try this...been on jury duty.
Reply With Quote
Reply

Tags
word 2010, word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through files and Copy Table Row and Paste into Different Document Is it possible to copy non-contiguous rows of a Table and paste them as a separate Table in Word? Joey Cheung Word Tables 1 08-12-2014 05:15 PM
Loop through files and Copy Table Row and Paste into Different Document Protection disappears when I copy and paste table to web AngieS Word Tables 1 09-29-2013 06:09 PM
OneNote - Copy and paste image to the table MartinK OneNote 0 09-03-2013 05:08 AM
Copy and paste table Patrickjm Word 1 03-19-2013 03:30 PM
Loop through files and Copy Table Row and Paste into Different Document Copy/Paste/Delete Table & Section etc. flds Word VBA 40 07-16-2011 07:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft