Results 1 to 3 of 3

Thread: [RESOLVED] Excel, (Shape) Label on sheet - caption changing

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Resolved [RESOLVED] Excel, (Shape) Label on sheet - caption changing

    Hi,

    How do I change the caption on a label that is on a sheet (not on a form) ?



    I've tried:

    shp <<< defined as a shape
    Code:
        For lngS = 1 To ActiveWorkbook.Sheets.Count
            Set sht = ActiveWorkbook.Sheets(lngS)
            
            On Error Resume Next
            Set shp = sht.Shapes("lblLastMonth")
            shp.Caption = "(May 2012)" 'errors
            shp.TextFrame.Characters.Text = "(May 2012)" ' errors
            On Error GoTo 0
        Next
    Any links or how to fix please? (I have the same label on multiple sheets, and want the code to flip through the sheets and change the caption on the label.

    Recording a macro doesn't store (the property window must not be recorded).



    Thanks in advance

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel, (Shape) Label on sheet - caption changing

    the shape contains an oleobject that contains the lable

    try like
    vb Code:
    1. shp.oleformat.object.object.caption = "(May 2012)"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Excel, (Shape) Label on sheet - caption changing

    Darn, wish I'd popped here first...


    Thanks westconn1

    I had the thought that maybe it was embedding a userform and I could get to it via that.

    But then I noticed the oleobject bit so I experimented with that and finally got to :
    Code:
        Dim lngS As Long
        Dim sht As Worksheet
        Dim shp As Shape
        Dim objOle As OLEObject
        
        For lngS = 1 To ActiveWorkbook.Sheets.Count
            Set sht = ActiveWorkbook.Sheets(lngS)
            
            On Error Resume Next
            
            Set objOle = sht.OLEObjects("lbllastmonth")
            objOle.Object = "(May 2012)"
            
            On Error GoTo 0
        Next
        
        
        Set shp = Nothing
        Set objOle = Nothing
        Set sht = Nothing
    This worked and now (as usual) I check here and the answer is waiting too lol.

    Thanks for posting westconn

    Edit:
    Sorry - cannot add to your rep - says I need to give it to others before I can... :/ So :thumbsup:

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width