If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.



Macro for table problems

Microsoft Word Forum

Microsoft Word Forum - Macro for table problems



Microsoft Word Forum Microsoft Word Forum


Reply
  #1  
Old 10-08-2006, 01:24 PM
john@johnhands.com
Guest
 
Posts: n/a
Macro for table problems

Hi Everybody

I've created a table specifying all the properties in Word for Mac
2004.

Since I use the format for this particular table frequently, I've tried
without success to create a macro for it.

I create a macro, insert Table (2 columns x 1 row), go to Table
Properties, tick Preferred Width box and specify width, specify Indent
from Left, go to Borders and Shading and specify No Borders, but then
find that the Preferred Width and Indent measurements have disappeared.
If I do it in reverse order, and then tab Row, I also lose the ticked
Preferred Width measurements. If I go through and complete the other
specs, and go back to Table, the macro doesn't produce the required
table, but seems to insert some properties of its own, like width of
column.

Since the original table appears in the document, I assume that its
properties are valid.

I'll be indebted for advice.

Many thanks

John

Reply With Quote
  #2  
Old 10-08-2006, 02:45 PM
Daiya Mitchell
Guest
 
Posts: n/a
Macro for table problems

One approach, and the one usually recommended for repeating tables:

Forgot the macro (which will break in the next version, anyhow), and save
your custom table as an AutoText (Select it, Insert | AutoText | New, I
think). More info:
http://word.mvps.org/FAQs/Customization/AutoText.htm
(hit reload a few times in Safari, or use a different browser)

I think Bend Word to Your Will may also have notes on this:
http://word.mvps.org/mac/bend/bendwordtoyourwill.html

On 10/8/06 6:24 AM, "john@johnhands.com" wrote:


--
Daiya Mitchell, MVP Mac/Word
Word FAQ: http://www.word.mvps.org/
MacWord Tips: <http://word.mvps.org/Mac/WordMacHome.html>
What's an MVP? A volunteer! Read the FAQ: http://mvp.support.microsoft.com/

Reply With Quote
  #3  
Old 10-08-2006, 03:18 PM
john@johnhands.com
Guest
 
Posts: n/a
Macro for table problems

Thanks, Dailya. The reason I tried a macro (which MIcrosoft Support
recommended) was that I'd alrady tried Autotext. When I used this, it
produced borders although the table I'd selected had none, and (if I
remember correctly) it didn't have bold in one column as did the
selected table.

John

Daiya Mitchell wrote:

Reply With Quote
  #4  
Old 10-08-2006, 05:58 PM
Beth Rosengard
Guest
 
Posts: n/a
Macro for table problems

Hi John,

I always use AutoCorrect instead of AutoText for these things (habit). I
just tried it with a table that had no borders at all and with bold in just
one cell. It reproduces fine.

I don't know why AutoText isn't working for you but try AutoCorrect and see
if it makes a difference.

By the way, when you get rid of table borders, they turn gray; they don't
actually disappear (except when you print). Could that be what you're
seeing?

--
***Please always reply to the newsgroup!***

Beth Rosengard
MacOffice MVP

Mac Word FAQ: <http://word.mvps.org/Mac/WordMacHome.html>
My Site: <http://www.bethrosengard.com>




On 10/8/06 8:18 AM, in article
1160320690.065921.236980@i3g2000cwc.googlegroups.c om, "john@johnhands.com"
<john@johnhands.com> wrote:


Reply With Quote
  #5  
Old 10-08-2006, 06:37 PM
john@johnhands.com
Guest
 
Posts: n/a
Macro for table problems

Hi Beth

No. I wasn't seeing grey lines, but solid black ones that printed.
But I'll try AutoCorrect instead.

Many thanks

John
Beth Rosengard wrote:

Reply With Quote
  #6  
Old 10-09-2006, 09:03 AM
John McGhie [MVP - Word and Word Macintosh]
Guest
 
Posts: n/a
Macro for table problems

Hi John:

You do NOT want to do the macro! Here's why... (Yes, it works :-))

Sub Main()
'
' Insert or Format Table Macro
' Macro recorded 14/03/00 by John McGhie
'
' On Error GoTo Error

Dim astyle As Style
Dim aDoc As String
Dim aTemplate As String
Dim x As Integer
Dim TabBodyText As Style
Dim TabHeading As Style
Dim TabBullet As Style
Dim tabNumber As Style


aTemplate = ActiveDocument.AttachedTemplate.FullName
aDoc = ActiveDocument.FullName
For Each astyle In ActiveDocument.Styles
If UCase(astyle.NameLocal) = UCase("Table Body Text") Then Set
TabBodyText = astyle
If UCase(astyle.NameLocal) = UCase("Table Bullet") Then Set TabBullet =
astyle
If UCase(astyle.NameLocal) = UCase("Table Heading") Then Set TabHeading
= astyle
If UCase(astyle.NameLocal) = UCase("Table Number") Then Set tabNumber =
astyle
Next astyle

If TabBodyText Is Nothing Then
ActiveDocument.Styles.Add Name:="Table Body Text"
Set TabBodyText = ActiveDocument.Styles("Table Body Text")
With TabBodyText
.AutomaticallyUpdate = False
.BaseStyle = "Body Text"
.NextParagraphStyle = "Table Body Text"
End With
With TabBodyText.Font
.Name = BodyFont
.Size = 10
.Bold = False
.Italic = False
End With
With TabBodyText.ParagraphFormat
.LeftIndent = 0
.RightIndent = 0
.SpaceBefore = 2
.SpaceBeforeAuto = False
.SpaceAfter = 2
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = True
.PageBreakBefore = False
.FirstLineIndent = 0
.OutlineLevel = wdOutlineLevelBodyText
End With
End If

If TabHeading Is Nothing Then
ActiveDocument.Styles.Add Name:="Table Heading"
Set TabHeading = ActiveDocument.Styles("Table Heading")
With TabHeading
.AutomaticallyUpdate = False
.BaseStyle = "Table Body Text"
.NextParagraphStyle = "Table Heading"
End With
With TabHeading.Font
.Name = HeadingFont
.Size = 10
.Bold = True
.Italic = False
End With
With TabHeading.ParagraphFormat
.LeftIndent = 0
.RightIndent = 0
.SpaceBefore = 2
.SpaceBeforeAuto = False
.SpaceAfter = 2
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = True
.KeepTogether = True
.PageBreakBefore = False
.FirstLineIndent = 0
.OutlineLevel = wdOutlineLevelBodyText
End With
End If

If TabBullet Is Nothing Then
ActiveDocument.Styles.Add Name:="Table Bullet"
Set TabBullet = ActiveDocument.Styles("Table Bullet")
With TabBullet
.AutomaticallyUpdate = False
.BaseStyle = "Table Body Text"
.NextParagraphStyle = "Table Bullet"
End With
With TabBullet.Font
.Name = BodyFont
.Size = 10
.Bold = False
.Italic = False
End With
With TabBullet.ParagraphFormat
.LeftIndent = 22
.RightIndent = 0
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 5
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.FirstLineIndent = -17
.OutlineLevel = wdOutlineLevelBodyText
End With
TabBullet.ParagraphFormat.TabStops.ClearAll
TabBullet.ParagraphFormat.TabStops.Add _
Position:=22, Alignment:=wdAlignTabLeft, Leader:= _
wdTabLeaderSpaces
With ListGalleries(wdBulletGallery).ListTemplates(7).Li stLevels(1)
.NumberFormat = ChrW(61623)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = 6
.Alignment = wdListLevelAlignLeft
.TextPosition = 22
.TabPosition = 22
.ResetOnHigher = 0
.StartAt = 1
.Font.Name = "Symbol"
.LinkedStyle = "Table Bullet"
End With
End If

If tabNumber Is Nothing Then
ActiveDocument.Styles.Add Name:="Table Number"
Set tabNumber = ActiveDocument.Styles("Table Number")

With tabNumber
.AutomaticallyUpdate = False
.BaseStyle = "Table Bullet"
.NextParagraphStyle = "Table Number"
End With
With tabNumber.Font
.Name = BodyFont
.Size = 10
.Bold = False
.Italic = False
End With
With tabNumber.ParagraphFormat
.LeftIndent = 22
.RightIndent = 0
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 2
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.FirstLineIndent = -17
.OutlineLevel = wdOutlineLevelBodyText
End With
tabNumber.ParagraphFormat.TabStops.ClearAll
tabNumber.ParagraphFormat.TabStops.Add _
Position:=22, Alignment:=wdAlignTabLeft, Leader:= _
wdTabLeaderSpaces
With ListGalleries(wdNumberGallery).ListTemplates(7).Li stLevels(1)
.NumberFormat = "%1."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = 6
.Alignment = wdListLevelAlignLeft
.TextPosition = 22
.TabPosition = 22
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = "Table Number"
End With
End If

If Not Selection.Information(wdWithInTable) Then
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=5,
NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
End If

Dim aTable As Table
Set aTable = Selection.Tables(1)

aTable.Select
aTable.AutoFormat Format:=wdTableFormatGrid5, ApplyBorders:= _
True, ApplyShading:=True, ApplyFont:=False, ApplyColor:=False, _
ApplyHeadingRows:=True, ApplyLastRow:=False,
ApplyFirstColumn:=False, _
ApplyLastColumn:=False, AutoFit:=True

aTable.Select

With Selection
.Rows.AllowBreakAcrossPages = False
.Paragraphs.Reset
.Font.Reset
.Style = ActiveDocument.Styles("Table Body Text")
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = wdColorAutomatic
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth025pt
.DefaultBorderColor = wdColorAutomatic
End With

aTable.Rows(1).Select
With Selection
.Style = ActiveDocument.Styles("Table Heading")
.Rows(1).HeadingFormat = True
With .Shading
.Texture = wdTexture10Percent
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorAutomatic
End With
End With

aTable.AutoFitBehavior (wdAutoFitWindow)

End

Error:
MsgBox "The Template has been damaged. See Tech Support.", vbCritical

End Sub



On 9/10/06 4:37 AM, in article
1160332667.937426.263970@h48g2000cwc.googlegroups. com, "john@johnhands.com"
<john@johnhands.com> wrote:


--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <john@mcghie.name>
Microsoft MVP, Word and Word for Macintosh. Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410


Reply With Quote
  #7  
Old 10-09-2006, 01:43 PM
john@johnhands.com
Guest
 
Posts: n/a
Macro for table problems

Hi John

Maybe I'm dumb, but I didn't understand what that progamming language
meant or why the macro does not work.

But if it doesn't work, then what is the best way to insert a specific
table format that I use repeatedly?

John

John McGhie [MVP - Word and Word Macintosh] wrote:

Reply With Quote
  #8  
Old 10-09-2006, 01:48 PM
john@johnhands.com
Guest
 
Posts: n/a
Macro for table problems

Hi John

Maybe I'm dumb, but I didn't understand what that progamming language
meant or why the macro does not work.

But if it doesn't work, then what is the best way to insert a specific
table format that I use repeatedly?

John

John McGhie [MVP - Word and Word Macintosh] wrote:

Reply With Quote
  #9  
Old 10-09-2006, 02:40 PM
Clive Huggan
Guest
 
Posts: n/a
Macro for table problems

On 9/10/06 11:48 PM, in article
1160401736.703976.302580@b28g2000cwb.googlegroups. com, "john@johnhands.com"
<john@johnhands.com> wrote:

<snip>
Hello John,

One way, by AutoText, is described blow-by-blow under the heading 'Example ‹
creating and inserting a pre-formatted table via AutoText' on page 124 of
some notes on the way I use Word for the Mac, titled "Bend Word to Your
Will", which are available as a free download from the Word MVPs' website
(http://word.mvps.org/Mac/Bend/BendWordToYourWill.html).

[Note: "Bend Word to your will" is designed to be used electronically and
most subjects are self-contained dictionary-style entries. If you decide to
read more widely than the item I've referred to, it's important to read the
front end of the document -- especially pages 3 and 5 -- so you can select
some Word settings that will allow you to use the document effectively.]

Cheers,

Clive Huggan
Canberra, Australia
(My time zone is 5-11 hours different from the US and Europe, so my
follow-on responses to those regions can be delayed)
================================================== ==========
Avoid long delays before your post appears -- use Entourage or newsreader
software -- see http://word.mvps.org/Mac/AccessNewsgroups.html
================================================== ==========


Reply With Quote
  #10  
Old 10-10-2006, 11:24 AM
John McGhie [MVP - Word and Word Macintosh]
Guest
 
Posts: n/a
Macro for table problems

If you pasted directly from your browser into the Visual Basic Editor, it
would convert the "spaces" into "non-breaking spaces". These are different
characters: a non-breaking space is significant in VBA.

To fix that, paste the code into SimpleText, save as Text Only, re-open it,
and paste from there. Then, any line that turns red has been folded over.
Delete the line-ender at the end of the first red line until it joins the
line below it. That should fix it.

Let me do that bit for you: There's a little attachment on this post. Save
it to your hard drive. In the VBA Editor, go to the Insert menu, choose
"File" and select this file. It will import into the Visual Basic Editor
correctly for you.

And no, you are not dumb: but that's a fairly advanced piece of code. Not
recommended for your first venture into VBA :-)

Now, do what Clive says: it's a LOT easier :-)

Cheers

On 9/10/06 11:43 PM, in article
1160401438.567270.98440@i42g2000cwa.googlegroups.c om, "john@johnhands.com"
<john@johnhands.com> wrote:


--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <john@mcghie.name>
Microsoft MVP, Word and Word for Macintosh. Business Analyst, Consultant
Technical Writer.
Sydney, Australia +61 (0) 4 1209 1410


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro vs Pivot table problem Snoopy Microsoft Excel Forum 1 05-30-2009 05:22 PM
Pivot table or Macro? Bobby Microsoft Excel Forum 2 01-24-2009 05:16 PM
Pivot Table by Macro? Roger Converse Microsoft Excel Forum 0 11-07-2007 08:56 PM
Using Macro to Alter Pivot Table Jasper Microsoft Excel Forum 1 03-01-2005 12:34 PM
Excel table macro Shiraz Mistry Microsoft Excel Forum 3 06-30-2003 09:13 AM


All times are GMT. The time now is 09:10 PM. Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. Copyright 2007-20011 Internet Computer Forum






Page generated in 0.37598 seconds with 9 queries