Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Error when I run Macro from QAT (Quick Access Toolbar)

Status
Not open for further replies.

afelissimo

Instructor
Sep 2, 2010
12
US
The macro works just fine from the macro button on the developer tab (Word 2007), but when I put the macro on the QAT and try to run it from there I get an error message. The error message has no text, just a big red circle with a white "x". ????

Can't find anything in google or tek-tips searches.

Please help!

Thanks in advance.
 
It may help if we could see what the code is.

Gerry

Och ammmmm, I think I need a shave.
- hirsute Scot, trying to decide
 
Hi Fumei!

Here's the code:

Code:
Sub Envelope()
[green]'
' Envelope Macro -- Keystroke shortcut = Alt+E
' Creates 8.5 x 11 inch foldable envelope insert
' with company return address and highlighted text as addressee
'
    'Copies highlighted text[/green]
    Selection.Copy
        
    [green]'Opens a new blank document and changes the empty paragraph formatting[/green]
    Documents.Add DocumentType:=wdNewBlankDocument
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Font.Name = "Times New Roman"
    Selection.Font.Size = 12
    Selection.ParagraphFormat.SpaceAfter = 0
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
        
        [green]'Changes document margins[/green]
        With ActiveDocument.PageSetup
                          
            .TopMargin = InchesToPoints(0.3)
            .BottomMargin = InchesToPoints(0.3)
            .LeftMargin = InchesToPoints(0.3)
            .RightMargin = InchesToPoints(0.3)
                 
        End With
        
    [green]'Creates a table[/green]
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
            2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
            wdAutoFitFixed
        
    [green]'Selects table and gets rid of visible borders[/green]
    Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
    Selection.Move Unit:=wdRow, Count:=1
    
    [green]'Sets table row heights[/green]
    ActiveDocument.Tables(1).Rows(1).Height = InchesToPoints(7.13)
    ActiveDocument.Tables(1).Rows(2).Height = InchesToPoints(1.25)
    ActiveDocument.Tables(1).Rows(3).Height = InchesToPoints(0.18)
    ActiveDocument.Tables(1).Rows(4).Height = InchesToPoints(1.61)
    
    [green]'Sets cell formatting[/green]
    With ActiveDocument.Tables(1).Rows(2).Cells(1)
        .VerticalAlignment = wdCellAlignVerticalCenter
            
            Dim aCell As Cell
            Set aCell = ActiveDocument.Tables(1).Cell(2, 1)
                aCell.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                 
                [green]'Adds text to cell 2,1[/green]
                .Range.Text = "Company Name" & vbCr & "ATTORNEYS AT LAW" & vbCr & "First Line of Address" & vbCr & "NEW YORK, NEW YORK  10038"
                    
                    [green]'Formats text in cell 2,1[/green]
                    aCell.Range.Font.Name = "Garamond"
                    aCell.Range.Font.Size = 10
                    
                        Dim FirstLine As Paragraph
                        Set FirstLine = ActiveDocument.Tables(1).Cell(2, 1).Range.Paragraphs(1)
                        
                            FirstLine.Range.Font.Size = 13
                            FirstLine.Range.Font.SmallCaps = True
                        
    End With
    
   [green]'Sets cell formatting[/green]
   With ActiveDocument.Tables(1).Rows(4).Cells(1)
        .VerticalAlignment = wdCellAlignVerticalCenter
        
        [green]'More cell formatting and paste special unformatted text from clipboard into cell[/green]
        Dim bCell As Cell
        Set bCell = ActiveDocument.Tables(1).Cell(4, 1)

            bCell.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
            bCell.Range.ParagraphFormat.LeftIndent = InchesToPoints(0.25)
            bCell.Range.Font.Size = 10
            bCell.Range.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
            wdInLine, DisplayAsIcon:=False
    End With
       
    [green]'Creates two fold lines[/green]
    ActiveDocument.Shapes.AddConnector(msoConnectorStraight, 1.05, 101.65, _
        609.9, 0#).Select
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.ConnectorFormat.Type = msoConnectorStraight
    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.Rotation = 0#
    Selection.ShapeRange.Left = 0.7
    Selection.ShapeRange.Top = 101.5
    Selection.ShapeRange.RelativeHorizontalPosition = _
        wdRelativeHorizontalPositionColumn
    Selection.ShapeRange.RelativeVerticalPosition = _
        wdRelativeVerticalPositionPage
    Selection.ShapeRange.RelativeHorizontalSize = wdRelativeHorizontalSizePage
    Selection.ShapeRange.RelativeVerticalSize = wdRelativeVerticalSizePage
    Selection.ShapeRange.Left = InchesToPoints(-0.29)
    Selection.ShapeRange.LeftRelative = wdShapePositionRelativeNone
    Selection.ShapeRange.Top = InchesToPoints(3.05)
    Selection.ShapeRange.TopRelative = wdShapePositionRelativeNone
    Selection.ShapeRange.WidthRelative = wdShapeSizeRelativeNone
    Selection.ShapeRange.HeightRelative = wdShapeSizeRelativeNone
    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.Line.ForeColor.ObjectThemeColor = _
        wdThemeColorBackground1
    Selection.ShapeRange.Line.ForeColor.TintAndShade = -0.25
    Selection.ShapeRange.Line.Visible = msoTrue
    ActiveWindow.ActivePane.VerticalPercentScrolled = 24
    ActiveDocument.Shapes.AddConnector(msoConnectorStraight, 0.7, 392.8, _
        609.9, 0#).Select
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.ConnectorFormat.Type = msoConnectorStraight
    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.Rotation = 0#
    Selection.ShapeRange.Left = 0.7
    Selection.ShapeRange.Top = 393.1
    Selection.ShapeRange.RelativeHorizontalPosition = _
        wdRelativeHorizontalPositionColumn
    Selection.ShapeRange.RelativeVerticalPosition = _
        wdRelativeVerticalPositionPage
    Selection.ShapeRange.RelativeHorizontalSize = wdRelativeHorizontalSizePage
    Selection.ShapeRange.RelativeVerticalSize = wdRelativeVerticalSizePage
    Selection.ShapeRange.Left = InchesToPoints(-0.29)
    Selection.ShapeRange.LeftRelative = wdShapePositionRelativeNone
    Selection.ShapeRange.Top = InchesToPoints(6.65)
    Selection.ShapeRange.TopRelative = wdShapePositionRelativeNone
    Selection.ShapeRange.WidthRelative = wdShapeSizeRelativeNone
    Selection.ShapeRange.HeightRelative = wdShapeSizeRelativeNone
    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.Line.ForeColor.ObjectThemeColor = _
        wdThemeColorBackground1
    Selection.ShapeRange.Line.ForeColor.TintAndShade = -0.25
    Selection.ShapeRange.Line.Visible = msoTrue
End Sub
 
Ah, you have the other post, yes? And you do not seem to be taking my suggestion about simplifying things.

Well, so it goes. At the very least you may want to try using With statements with all that extraneous code.

As for your issue with the QAT, I do not think I can help you.

Have you tried stepping through the code?

Gerry

Och ammmmm, I think I need a shave.
- hirsute Scot, trying to decide
 
I could probably clean up the code for the table borders, and I know that I could clean up the code for the shapes. I just have to be careful with the shapes that I don't accidentally delete something that I need.

And, yes, I think this QAT issue is separate from the code, since the code is working well from the macro button on the developer tab.

Thanks for your help with the other problems!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top