Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2011, 09:23 PM
macropod's Avatar
macropod macropod is offline Copy/Paste/Delete Table & Section etc. Windows 7 32bit Copy/Paste/Delete Table & Section etc. Office 2007
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

Hi flds,



Try:
Code:
Sub Main()
Dim TOC As TableOfContents
With ActiveDocument
  For Each TOC In .TablesOfContents
    TOC.Delete
  Next
  .Fields.Unlink 
  Call MoveTablesToNewDocument
  With .Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^b"
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
    .Text = "^~"
    .Replacement.Text = "-"
    .Execute Replace:=wdReplaceAll
  End With
End With
End Sub
Code:
Sub MoveTablesToNewDocument()
Dim SrcDoc, NewDoc As Document
Dim SrcDocTableRange As Range
Set SrcDoc = ActiveDocument
If SrcDoc.Tables.Count <> 0 Then
  Set NewDoc = Documents.Add(DocumentType:=wdNewBlankDocument)
  Set NewDocRange = NewDoc.Range
  Dim PrevPara As Range
  Dim NextPara As Range
  Dim NextEnd As Long
  NextEnd = 0
  With NewDocRange
    For Each SrcDocTable In SrcDoc.Tables
      Set SrcDocTableRange = SrcDocTable.Range
      'output the preceding paragraph?
      Set PrevPara = SrcDocTableRange.Previous(wdParagraph, 1)
      If PrevPara Is Nothing Or PrevPara.Start < NextEnd Then
      Else
        Set PPWords = PrevPara.Words
        If PPWords.Count > 1 Then 'yes
          .Start = NewDocRange.End
          .InsertParagraphBefore
          .Start = NewDocRange.End
          .InsertParagraphBefore
          .FormattedText = PrevPara.FormattedText
        End If
      End If
      'output the table
      .Start = .End
      .FormattedText = SrcDocTableRange.FormattedText
      'output the following paragraph?
      Set NextPara = SrcDocTableRange.Next(wdParagraph, 1)
      If NextPara Is Nothing Then
      Else
        Set PPWords = NextPara.Words
        NextEnd = NextPara.End
        If PPWords.Count > 1 Then 'yes
          .Start = .End
          .InsertParagraphBefore
          .FormattedText = NextPara.FormattedText
        End If
      End If
      SrcDocTableRange.Delete
    Next SrcDocTable
  End With
End If
End Sub
PS: When posting code, please use code tags and formatted code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 06-08-2011 at 09:55 PM. Reason: Minor code revision - TOC variable and loop in 1st module
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy/Paste/Delete Table &amp; Section etc. copy and paste not working Ellie Word 3 11-07-2013 02:23 PM
Can't copy paste irenasobolewska Office 2 10-26-2012 05:09 PM
Copy - Paste between 2 tables rod147 Excel 1 10-22-2009 08:21 PM
Copy & paste low resolution worriedme Drawing and Graphics 0 06-01-2009 03:05 AM
Copy/Paste/Delete Table &amp; Section etc. Copy and paste special Dace Excel 2 02-16-2009 12:18 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:29 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