Results 1 to 9 of 9

Thread: [RESOLVED] Excel Chart Textbox with Formula

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Resolved [RESOLVED] Excel Chart Textbox with Formula

    I add a textbox in the lower right hand corner of a chart for supplemental information. This code snippet works:

    Code:
            Set tb = ActiveChart.Shapes.AddTextbox _
                     (msoTextOrientationHorizontal, _
                     ActiveChart.ChartArea.width - 125, _
                     ActiveChart.ChartArea.Height - 22, _
                     124, _
                     21)
             
            With tb
                .Fill.BackColor.RGB = RGB(225, 225, 225)
                .TextFrame.HorizontalAlignment = xlHAlignCenter
                .TextFrame.VerticalAlignment = xlVAlignCenter
            End With 'textbox "frame"
            
            tb.Select
            Selection.Formula = "='peak detect'!$I$2"
    where "peak detect" is my source page for the formula. Look at the last two lines. Why do I have to do this? For some reason I have to select the shape object to set the formula. I can't find any other way to set the formula property of a textbox.

    Thank you

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

    Re: Excel Chart Textbox with Formula

    i do not believe that textboxes have a formula property, possibly like

    vb Code:
    1. With tb
    2.             .Fill.BackColor.RGB = RGB(225, 225, 225)
    3.             .TextFrame.HorizontalAlignment = xlHAlignCenter
    4.             .TextFrame.VerticalAlignment = xlVAlignCenter
    5.             .textfame.range.text =  "='peak detect'!$I$2"
    6.         End With
    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
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Re: Excel Chart Textbox with Formula

    Sorry,

    That doesn't work.

  4. #4
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Excel Chart Textbox with Formula

    what is the problem with your method?

    here to think

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Re: Excel Chart Textbox with Formula

    I'm just bamboozled that I have to "select" the textbox to assign it a formula. Why does the act of selecting suddenly give me access to the formula property?

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

    Re: Excel Chart Textbox with Formula

    try
    vb Code:
    1. tb.oleformat.object.formula =  "='peak detect'!$I$2"
    i tested this
    Last edited by westconn1; Feb 16th, 2012 at 05:03 AM.
    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Re: Excel Chart Textbox with Formula

    westconn1,

    Beautimus!
    Thank you!

    PS - how did you find this? I've been mucking through the object model for days with no luck ...

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

    Re: [RESOLVED] Excel Chart Textbox with Formula

    i checked in the locals window
    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Re: [RESOLVED] Excel Chart Textbox with Formula

    pete aka westconn1.
    Thanks again!

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