Link to home
Start Free TrialLog in
Avatar of FAFitzgerald
FAFitzgerald

asked on

Macro Doesn't Work in Word 2007

User has a macro that inserts and formats a text box in a Word document.  The Macro works great in Word 2003 and it works in Word 2007 when in compatibility mode.  When the user converts the document to the new .docm format the macro stops working.  The macro errors out with a Run-Time error '5917' - this object does not support attached text.

It appears as though the script fails because there are multiple text boxes in the document.  The macro will add the text box but the formatting fails.  Looks like the macro may be trying to format one of the other text boxes.  If I delete all the text boxes from the document then the macro runs just fine.  Anyone have any ideas?  Thanks!
Sub Paste()
'
' Paste Macro
' Macro recorded 8/1/2008 by userid
'
    Selection.ShapeRange.IncrementLeft 290.45
    Selection.ShapeRange.IncrementTop 3.25
    Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 1.5
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.LockAspectRatio = msoTrue
    Selection.ShapeRange.Rotation = 0#
    Selection.ShapeRange.PictureFormat.Brightness = 0.5
    Selection.ShapeRange.PictureFormat.Contrast = 0.5
    Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic
    Selection.ShapeRange.PictureFormat.CropLeft = 0#
    Selection.ShapeRange.PictureFormat.CropRight = 0#
    Selection.ShapeRange.PictureFormat.CropTop = 0#
    Selection.ShapeRange.PictureFormat.CropBottom = 0#
    Selection.ShapeRange.Left = 318.95
    Selection.ShapeRange.Top = 44.6
    Selection.ShapeRange.RelativeHorizontalPosition = _
        wdRelativeHorizontalPositionColumn
    Selection.ShapeRange.RelativeVerticalPosition = _
        wdRelativeVerticalPositionParagraph
    Selection.ShapeRange.Left = InchesToPoints(3.93)
    Selection.ShapeRange.Top = InchesToPoints(0.12)
    Selection.ShapeRange.LockAnchor = False
    Selection.ShapeRange.LayoutInCell = True
    Selection.ShapeRange.WrapFormat.AllowOverlap = True
    Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
    Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.Type = wdWrapTight
End Sub
Sub CallOut()
'
' CallOut Macro
' Macro recorded 8/1/2008 by userid
'
    ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 251.6, _
        84.95, 16.2, 17#).Select
    Selection.ShapeRange.TextFrame.TextRange.Select
    Selection.Collapse
    With Selection.ParagraphFormat
        .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
        .Borders(wdBorderRight).LineStyle = wdLineStyleNone
        .Borders(wdBorderTop).LineStyle = wdLineStyleNone
        .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
        With .Borders
            .DistanceFromTop = 1
            .DistanceFromLeft = 4
            .DistanceFromBottom = 1
            .DistanceFromRight = 4
            .Shadow = False
        End With
    End With
    With Options
        .DefaultBorderLineStyle = wdLineStyleSingle
        .DefaultBorderLineWidth = wdLineWidth050pt
        .DefaultBorderColor = wdColorAutomatic
    End With
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.LockAspectRatio = msoFalse
    Selection.ShapeRange.Height = 17.3
    Selection.ShapeRange.Width = 16.55
    Selection.ShapeRange.Left = 251.25
    Selection.ShapeRange.Top = 84.95
    Selection.ShapeRange.TextFrame.MarginLeft = 0.72
    Selection.ShapeRange.TextFrame.MarginRight = 0.72
    Selection.ShapeRange.TextFrame.MarginTop = 0.72
    Selection.ShapeRange.TextFrame.MarginBottom = 0.72
    Selection.ShapeRange.RelativeHorizontalPosition = _
        wdRelativeHorizontalPositionColumn
    Selection.ShapeRange.RelativeVerticalPosition = _
        wdRelativeVerticalPositionParagraph
    Selection.ShapeRange.Left = InchesToPoints(2.99)
    Selection.ShapeRange.Top = InchesToPoints(0.68)
    Selection.ShapeRange.LockAnchor = False
    Selection.ShapeRange.LayoutInCell = True
    Selection.ShapeRange.WrapFormat.AllowOverlap = True
    Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
    Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
    Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
    Selection.ShapeRange.WrapFormat.Type = 3
    Selection.ShapeRange.ZOrder 4
    Selection.ShapeRange.TextFrame.AutoSize = False
    Selection.ShapeRange.TextFrame.WordWrap = True
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="A"
    Selection.ShapeRange.Select
    Selection.ShapeRange.ScaleWidth 0.9, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight 0.91, msoFalse, msoScaleFromTopLeft
End Sub

Open in new window

Avatar of Joanne M. Orzech
Joanne M. Orzech
Flag of United States of America image

Probably the easiest thing to do is re-record the macro in 2007.
Avatar of FAFitzgerald
FAFitzgerald

ASKER

Yeah we tried that but it still errors out.
Well, I've tried it with text boxes, autoshapes, and images, and it doesn't recognize any of them.  You say she has "text" boxes inserted?  And we're sure they're plain old text boxes?
ASKER CERTIFIED SOLUTION
Avatar of FAFitzgerald
FAFitzgerald

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry - I can't seem to get it to work in either version.
Friends. I have a simular situation where I and formating a booklet from VFP in word. The text is placed in various tables for printing. Word 2007 broke the VB somewhere in the setwidth / setpointsto- formating. I needed to reload 2003 to run the process after spending hours trying to fix.
Please keep trying to find the solution