Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.tables
|
|||
|
|||
how do I combine these two macros?
I have two macros that I can't quite seem to combine. I want the macro
to add a new cell on the left of all Note style tables, and then to write the word "noteicon" in the new cell. This macro adds the text "noteicon" in the first cell of tables that have the "Note" style. Sub AddText() Dim oTbl As Table For Each oTbl In ActiveDocument.Tables If oTbl.Cell(1, 1).Range.Style = _ ActiveDocument.Styles("Note") Then With oTbl .Cell(1, 1).Range.InsertAfter "noteicon" End With End If Next oTbl End Sub This macro adds a new row in the first table. Sub AddCell() If Selection.Cells.Count = 1 Then Selection.InsertCells ShiftCells:=wdInsertCellsShiftRight End If End Sub Could someone show me how to combine these two macros into one? I want the AddCell macro to only add a cell in "Note" table, and then to write the word "noteicon" in the new cell. I've been trying to figure this out for days, but haven't been successful. Thanks for any help. |
#2
Posted to microsoft.public.word.tables
|
|||
|
|||
how do I combine these two macros?
Hi Tom
I'm not sure I understand exactly what you want. Is this it: Go through every table in the document. If the first cell in the table is in style "Note" then add a new row to the bottom of the table. Apply the style "Note" to the first cell in the last row. Insert the text "noteicon" in the first cell in the last row. Go to the next table and re-do. If that's not it, can you let us know just how you want the code to work? Hope this helps. Shauna Kelly. Microsoft MVP. http://www.shaunakelly.com/word "Tom" wrote in message ups.com... I have two macros that I can't quite seem to combine. I want the macro to add a new cell on the left of all Note style tables, and then to write the word "noteicon" in the new cell. This macro adds the text "noteicon" in the first cell of tables that have the "Note" style. Sub AddText() Dim oTbl As Table For Each oTbl In ActiveDocument.Tables If oTbl.Cell(1, 1).Range.Style = _ ActiveDocument.Styles("Note") Then With oTbl .Cell(1, 1).Range.InsertAfter "noteicon" End With End If Next oTbl End Sub This macro adds a new row in the first table. Sub AddCell() If Selection.Cells.Count = 1 Then Selection.InsertCells ShiftCells:=wdInsertCellsShiftRight End If End Sub Could someone show me how to combine these two macros into one? I want the AddCell macro to only add a cell in "Note" table, and then to write the word "noteicon" in the new cell. I've been trying to figure this out for days, but haven't been successful. Thanks for any help. |
#3
Posted to microsoft.public.word.tables
|
|||
|
|||
how do I combine these two macros?
New cell or new column? The following will add a new cell and types in that
cell 'Noteicon' - and effectively does what your two macros do. It makes no account for the amount of space available for an extra cell/column - but neither did the original. Swap the InsertColumns line for the InsertCells line to insert a new column to the left. Sub AddText() Dim oTbl As Table For Each oTbl In ActiveDocument.Tables If oTbl.Cell(1, 1).Range.Style = _ ActiveDocument.Styles("Note") Then oTbl.Cell(1, 1).Range.Select With Selection '.InsertColumns .InsertCells _ ShiftCells:=wdInsertCellsShiftRight .TypeText Text:="Noteicon" End With End If Next oTbl End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Tom wrote: I have two macros that I can't quite seem to combine. I want the macro to add a new cell on the left of all Note style tables, and then to write the word "noteicon" in the new cell. This macro adds the text "noteicon" in the first cell of tables that have the "Note" style. Sub AddText() Dim oTbl As Table For Each oTbl In ActiveDocument.Tables If oTbl.Cell(1, 1).Range.Style = _ ActiveDocument.Styles("Note") Then With oTbl .Cell(1, 1).Range.InsertAfter "noteicon" End With End If Next oTbl End Sub This macro adds a new row in the first table. Sub AddCell() If Selection.Cells.Count = 1 Then Selection.InsertCells ShiftCells:=wdInsertCellsShiftRight End If End Sub Could someone show me how to combine these two macros into one? I want the AddCell macro to only add a cell in "Note" table, and then to write the word "noteicon" in the new cell. I've been trying to figure this out for days, but haven't been successful. Thanks for any help. |
#4
Posted to microsoft.public.word.tables
|
|||
|
|||
how do I combine these two macros?
Thanks Graham and Shauna. Yes, I only need to insert a cell (my table
is only one row, with 2 columns or cells). Graham, the macro code you typed works perfectly -- except for the width issues, as you indicated. How would I define the width of the first and second cell? I'd like the first cell to be .75 inches and the second cell to be 5.25 inches. |
#5
Posted to microsoft.public.word.tables
|
|||
|
|||
how do I combine these two macros?
I specified the cell width by adding .Cells(1).Width = 22 below.
Sub NoteIcon() Dim oTbl As Table For Each oTbl In ActiveDocument.Tables If oTbl.Cell(1, 1).Range.Style = _ ActiveDocument.Styles("Note") Then oTbl.Cell(1, 1).Range.Select With Selection '.InsertColumns .InsertCells _ ShiftCells:=wdInsertCellsShiftRight .TypeText Text:="Noteicon" .Style = ActiveDocument.Styles("Notetable") .Cells(1).Width = 22 End With End If Next oTbl End Sub It should be easy to specify the width of the cell to its right (or to specify the column widths), but I keep getting errors. So I have resorted to this work around. Sub FormatNotes() Dim oTbl As Table For Each oTbl In ActiveDocument.Tables If oTbl.Cell(1, 1).Range.Style = _ ActiveDocument.Styles("Note") Then With oTbl .Style = ActiveDocument.Styles("Notetable") .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = 75 End With End If Next oTbl End Sub This macro sets the length of the entire table. Is there a more graceful way of doing both of these operations in one macro? |
#6
Posted to microsoft.public.word.tables
|
|||
|
|||
how do I combine these two macros?
Oh, I think I got it.
Sub NoteIcon() Dim oTbl As Table For Each oTbl In ActiveDocument.Tables If oTbl.Cell(1, 1).Range.Style = _ ActiveDocument.Styles("Note") Then oTbl.Cell(1, 1).Range.Select With Selection '.InsertColumns .InsertCells _ ShiftCells:=wdInsertCellsShiftRight .TypeText Text:="Noteicon" .Style = ActiveDocument.Styles("Notetable") .Cells(1).Width = 22 End With oTbl.Cell(1, 2).Range.Select With Selection '.InsertColumns .Cells(1).Width = 378 End With End If Next oTbl End Sub Thanks for all your help. Sorry that I keep replying to my own posts like this. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macros In This Project Are Disabled | New Users | |||
PLease Help!!!Formulas not updating and macros disappearing | Tables | |||
Enable Macros and ActiveX Errors starting Word 2003 | Microsoft Word Help | |||
New Word Macros won't run | Microsoft Word Help | |||
Macros in 2003 multiple but connected problems? | Microsoft Word Help |