Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 22,467
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
 

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 09:25 AM.


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