Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Folks, I have a customer with Word documents containing scores of notes consisting of an icon with text next to it.

    To conform to the company style, each note needs to be converted to a two-column, four-cell table with the icon in the bottom left cell and the text to the right. (Don's ask...)

    See the attached pic.

    Has anyone out there seen a macro that replaces a style with a table?

    Robocod

    [attachment=82730:convert.jpg]
    Attached Images Attached Images

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='Robocod' post='764211' date='08-Mar-2009 21:18'][/quote]
    Welcome to the Lounge!

    Could you attach a small sample document for Loungers to experiment with? Remove sensitive information from the document or replace it with dummy text.

  3. #3
    New Lounger
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sure. See the attached for a sample of a note before and after manual conversion.

    I've been able to make simple mods to a bunch of macros I've found on the net, but this task is way beyond me.

    Stephen
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='Robocod' post='764229' date='08-Mar-2009 22:28'][/quote]
    The following macro isn't very elegant, but it converts the notes to tables:
    Code:
    Sub AdjustNotes()
      Selection.HomeKey Unit:=wdStory
      With Selection.Find
    	.Text = ""
    	.ClearFormatting
    	.Style = "ntNote char"
    	.Format = True
    	Do While .Execute
    	  Selection.HomeKey Unit:=wdLine
    	  Selection.TypeText vbTab & vbCr
    	  Selection.MoveRight Unit:=wdCharacter
    	  Selection.TypeText vbTab
    	  Selection.Font.Bold = True
    	  Selection.Font.Italic = True
    	  Selection.TypeText "Note: "
    	  Selection.Font.Bold = False
    	  Selection.Font.Italic = False
    	  Selection.MoveStart Unit:=wdParagraph, Count:=-2
    	  Selection.MoveEnd Unit:=wdParagraph
    	  Selection.ConvertToTable Separator:=wdSeparateByTabs
    	  Selection.Tables(1).Columns(1).AutoFit
    	  Selection.MoveDown Unit:=wdLine
    	Loop
      End With
    End Sub

  5. #5
    New Lounger
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans, you just saved me days of effort! Thank you!

    Last question: how can I set the width of the second column to 402 points?

    Stephen

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='Robocod' post='764252' date='09-Mar-2009 01:06']Hans, you just saved me days of effort! Thank you!

    Last question: how can I set the width of the second column to 402 points?

    Stephen[/quote]
    Below the line that AutoFits the first column, insert the following:

    Selection.Tables(1).Columns(2).Width = 402

  7. #7
    New Lounger
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans, I'm sorry to bother you again after you wrote the macro for me that converts notes to tables (below), but I'm having trouble solving a problem.

    The macro works great, but seems to hit some kind of limit after processing perhaps a dozen notes. It fails with the message: "One of the values passed to this method or property is out of range" and it appears to be because it is attempting to create a new table inside a note it has just finished creating.

    Can you give me a clue about what is happening? I've attached part of the output that shows where the failure has occurred and the original segment. (Of course, running the macro on just this one piece works fine -- it's when this is one of a long series of notes that it fails on this one).

    Stephen Marino

    ---------------------

    Sub AdjustNotes()
    '
    ' AdjustNotes Macro
    ' Macro courtesy HansV March 8, 2009
    '
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .Text = ""
    .ClearFormatting
    .Style = "ntNote"
    .Format = True
    Do While .Execute
    Selection.HomeKey Unit:=wdLine
    Selection.TypeText vbTab & vbCr
    Selection.MoveRight Unit:=wdCharacter
    Selection.TypeText vbTab
    Selection.Font.Bold = True
    Selection.Font.Italic = True
    Selection.TypeText "Note: "
    Selection.Font.Bold = False
    Selection.Font.Italic = False
    Selection.MoveStart Unit:=wdParagraph, Count:=-2
    Selection.MoveEnd Unit:=wdParagraph
    Selection.ConvertToTable Separator:=wdSeparateByTabs
    Selection.TABLES(1).Columns(1).AutoFit
    Selection.TABLES(1).Columns(2).Width = 402
    With Selection.TABLES(1)
    .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
    .Borders(wdBorderRight).LineStyle = wdLineStyleNone
    .Borders(wdBorderTop).LineStyle = wdLineStyleNone
    With .Borders(wdBorderBottom)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorAutomatic
    End With
    With .Borders(wdBorderHorizontal)
    .LineStyle = wdLineStyleSingle
    .LineWidth = wdLineWidth050pt
    .Color = wdColorAutomatic
    End With
    .Borders(wdBorderVertical).LineStyle = wdLineStyleNone
    .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
    .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
    .Borders.Shadow = False
    End With
    With Options
    .DefaultBorderLineStyle = wdLineStyleSingle
    .DefaultBorderLineWidth = wdLineWidth050pt
    .DefaultBorderColor = wdColorAutomatic
    End With
    Selection.MoveDown Unit:=wdLine
    Loop
    End With
    End Sub
    Attached Files Attached Files

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I suspect that there are situations in which the line

    Selection.MoveDown Unit:=wdLine

    doesn't move the selection below the table, but leaves it inside the first table cell. You might single-step through the code to see whether this happens and if so, where - perhaps you'll notice something about the location in the document where this happens.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •