![]() |
|
#1
|
|||
|
|||
|
I have a table in a word document that I need to delete a specific row from. The user would input the row number they would want to delete and once the row is deleted then the row numbers in the column would re-number appropriately 1, 2, 3, 4, etc. The user would also not be able to delete the last row and the user would receive an error message if a row did not exist. I have been struggling with this for awhile and now I need to call in the big guns. Thanks in advance!
|
|
#2
|
||||
|
||||
|
Why not simply auto-number the rows and let the user select & delete the row?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thanks for the reply. I have the content control locked and I believe it is causing the table to be locked for editing. Right clicking the row the option to delete the row is greyed out. I love the idea of having a non VBA solution.
|
|
#4
|
|||
|
|||
|
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey Dim oTbl As Table Dim lngRow As Long Dim oCC As ContentControl Set oTbl = ActiveDocument.Tables(1) lngRow = CLng(InputBox("What row?")) For Each oCC In oTbl.Rows(lngRow).Range.ContentControls oCC.LockContentControl = False oCC.LockContents = False Next oTbl.Rows(lngRow).Delete oTbl.Range.Fields.Update 'I assume you have numbered the rows with a Seq Field. lbl_Exit: Exit Sub End Sub |
|
#5
|
||||
|
||||
|
I wasn't aware from your previous post that the content control was locked. Even then, it requires nothing more than unlocking it, which could be expedited with a macro like:
Code:
Sub Demo()
Dim CCtrl As ContentControl
With Selection
If .Information(wdWithInTable) = False Then Exit Sub
With .Rows(1)
For Each CCtrl In .Range.ContentControls
CCtrl.LockContentControl = False
CCtrl.LockContents = False
Next
.Delete
End With
End With
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#6
|
|||
|
|||
|
Yeah sorry about that I should have clarified.
Greg's solution worked like a champ. How about an error message if the row doesn't exist or it is the last row? |
|
#7
|
|||
|
|||
|
How about what have you tried?
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| User input box with IF statement | ChrisJ83 | Word VBA | 9 | 11-13-2015 06:20 PM |
| Variable arrays from user input | SeattleITguy | Excel Programming | 1 | 01-29-2015 09:19 AM |
vba: user input named argument
|
andrew12345 | Excel Programming | 2 | 11-18-2014 08:18 AM |
User input to a variable on the document
|
dsm1995gst | Word VBA | 1 | 09-03-2013 03:43 PM |
Replacing text with user input.?.?.?
|
brad1977 | Word | 3 | 11-20-2012 10:20 AM |