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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA: Looping through shapes on a worksheet

Status
Not open for further replies.

Aeneas

Programmer
Sep 18, 2003
25
CA
What I want to do is loop through all the shapes on a worksheet (for all worksheets in a workbook, I guess) and if they are textboxes, change some of the default formatting. I believe I have most of the code worked out, but am getting a runtime error that the object doesn't support being selected (object does not support this property or method) when I go to select it (the activesheet.shp.select line just a few down). Any suggestions? Code below:



Code:
For Each ws In ActiveWorkbook.Worksheets

    ws.Select

    For Each shp In ws.Shapes

        If shp.Type = msoTextBox Then
        
            ActiveSheet.shp.Select
            With Selection
                .HorizontalAlignment = xlJustify
                .VerticalAlignment = xlCenter
                .ShapeRange.TextFrame.MarginLeft = 7.09
                .ShapeRange.TextFrame.MarginRight = 7.09
                .ShapeRange.TextFrame.MarginTop = 3.69
                .ShapeRange.TextFrame.MarginBottom = 3.69
                .ShapeRange.Line.Weight = 0.25
                .ShapeRange.Fill.Visible = msoTrue
                .ShapeRange.Fill.Solid
                .ShapeRange.Fill.ForeColor.SchemeColor = 65
                .ShapeRange.Fill.Transparency = 0#
            End With
    
        End If
    
    Next shp

Next ws
 

Hi,

Need to manipulate the OLEFormat.Object of the shape...
Code:
    For Each ws In ActiveWorkbook.Worksheets
    
        For Each shp In ws.Shapes
    
            If shp.Type = msoTextBox Then
            
                With shp.OLEFormat.Object
                    .HorizontalAlignment = xlJustify
                    .VerticalAlignment = xlCenter
                    .ShapeRange.TextFrame.MarginLeft = 7.09
                    .ShapeRange.TextFrame.MarginRight = 7.09
                    .ShapeRange.TextFrame.MarginTop = 3.69
                    .ShapeRange.TextFrame.MarginBottom = 3.69
                    .ShapeRange.Line.Weight = 0.25
                    .ShapeRange.Fill.Visible = msoTrue
                    .ShapeRange.Fill.Solid
                    .ShapeRange.Fill.ForeColor.SchemeColor = 65
                    .ShapeRange.Fill.Transparency = 0#
                End With
        
            End If
        
        Next shp
    
    Next ws


Skip,

[glasses] [red]Be Advised![/red] For those this winter, caught in Arctic-like calamity, be consoled...
Many are cold, but few are frozen![tongue]
 
As always Skip, you have the simple and perfect answer. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top