Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default 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   Report Post  
Posted to microsoft.public.word.tables
Shauna Kelly Shauna Kelly is offline
external usenet poster
 
Posts: 571
Default 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   Report Post  
Posted to microsoft.public.word.tables
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default 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   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default 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   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default 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   Report Post  
Posted to microsoft.public.word.tables
Tom Tom is offline
external usenet poster
 
Posts: 61
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macros In This Project Are Disabled Lem New Users 3 April 3rd 06 09:53 AM
PLease Help!!!Formulas not updating and macros disappearing Kay Tables 7 February 2nd 06 09:41 AM
Enable Macros and ActiveX Errors starting Word 2003 GK Microsoft Word Help 2 June 19th 05 02:29 AM
New Word Macros won't run TexasBBQ Microsoft Word Help 6 May 23rd 05 11:12 PM
Macros in 2003 multiple but connected problems? V-ger Microsoft Word Help 8 January 18th 05 09:42 PM


All times are GMT +1. The time now is 11:10 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"