Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 07-18-2016, 01:29 AM
emmanpelayo emmanpelayo is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2015
Posts: 22
emmanpelayo is on a distinguished road
Default Duplicating table set in word


I was hoping to get help from this. Please see comments in review section. Thanks.
Attached Files
File Type: docm DRAFT Mercy Report.docm (121.7 KB, 5 views)
Reply With Quote
  #2  
Old 07-18-2016, 04:53 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,619
gmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the rough
Default

Add the following code to an ordinary module:
Code:
Option Explicit

Sub AddTable()
Dim oTable As Table
Dim oRng As Range
Dim oCell As Range
Dim i As Long
    ActiveDocument.Tables(ActiveDocument.Tables.Count).Range.Copy
    Set oRng = ActiveDocument.Tables(ActiveDocument.Tables.Count).Range
    oRng.End = oRng.End + 1
    oRng.Collapse 0
    oRng.Text = vbCr
    oRng.Collapse 0
    oRng.Paste
    For i = 1 To ActiveDocument.Tables(ActiveDocument.Tables.Count).Range.Cells.Count
        ActiveDocument.Tables(ActiveDocument.Tables.Count).Range.Cells(i).Select
        Select Case i
            Case Is = 3, 4, 5, 8, 10, 12
                Set oCell = ActiveDocument.Tables(ActiveDocument.Tables.Count).Range.Cells(i).Range
                oCell.End = oCell.End - 1
                oCell.Text = ""
            Case Else
        End Select
    Next i
    ActiveDocument.Tables(ActiveDocument.Tables.Count).Range.Cells(3).Select
End Sub
Then modify your existing macro to call it
Code:
Private Sub Document_ContentControlOnEnter(ByVal CCtrl As ContentControl)
    Application.ScreenUpdating = False
    Dim CCtrlRng As Range, TblRng As Range, i As Long, Prot As Variant, Pwd As String
    With ActiveDocument
        Set CCtrlRng = CCtrl.Range
        If CCtrlRng.Information(wdWithInTable) Then
            Set TblRng = CCtrlRng.Tables(1).Range
            i = .Range(0, TblRng.End).Tables.Count
            If (i < 3) Then Exit Sub
            If MsgBox("Add new SBAR set?", vbQuestion + vbYesNo) = vbYes Then
                Prot = .ProtectionType
                If Prot <> wdNoProtection Then
                    Pwd = ""    'Insert password here
                    .Unprotect Password:=Pwd
                End If
                AddTable
                .Protect Type:=Prot, Password:=Pwd
            End If
        End If
    End With
    Application.ScreenUpdating = True
End Sub
__________________
Graham Mayor - MS MVP (Word)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 08-08-2016, 08:41 PM
emmanpelayo emmanpelayo is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2015
Posts: 22
emmanpelayo is on a distinguished road
Default

Thanks heaps for this!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
duplicating field values in a word document howarths Word 5 11-05-2015 11:50 AM
Large Word doc duplicating large sections when I print it. Kea Word 3 05-30-2015 02:28 PM
Find/Replace, Duplicating a word in a sentence to hundreds of sentences. DDDD Word 0 10-08-2013 10:48 AM
Outlook Duplicating Sent Items eb123456 Outlook 0 02-15-2012 11:49 PM
Issue with Word duplicating cajun62234 Word 4 04-06-2011 07:12 PM


All times are GMT -7. The time now is 05:51 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft