+ Reply to Thread
Results 1 to 9 of 9

Problem with selection of Text Box

Hybrid View

  1. #1
    Registered User
    Join Date
    08-15-2014
    Location
    Slovakia
    MS-Off Ver
    7
    Posts
    6

    Problem with selection of Text Box

    Hello,

    I wrote a code that copy Text box from one sheet to another. Further in the code I need to delete this pasted TextBox. This is something I cannot do. It seems very simple, but I was unabe to find solution despite the fact that I was searching for it in past two days.

    I named the TextBox. But after it is pasted to differetnt sheet it changes its name. Furthermore it will become a picture and not editable text box. This is not a problem for me as I do not need to edit the text inside the box. But I think it might be the reason why the name is not preserved and why I got the error message that the object cannot be found.

    So what I am looking for is to be able to:

    Copy and paste Textbox from one sheet to another. (This I have)
    Delete the pasted Textbox. (this is the point where I have problems).

    I will appreciate any help....

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,192

    Re: Problem with selection of Text Box

    ActiveSheet.Shapes("TextBox1").Delete

  3. #3
    Registered User
    Join Date
    08-15-2014
    Location
    Slovakia
    MS-Off Ver
    7
    Posts
    6

    Re: Problem with selection of Text Box

    Hi,

    Thanks for the suggestion. However it doesnt work for me. Since I am working with multiple textboxes I dont want to rely on automatic numbering, but rather name them.
    The other thing is as I mentioned is that after pasting it is not textbox anymore. Is there any way how to paste the textbox and keep its original properties such as name and formatting?

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Problem with selection of Text Box

    Have to ask, why bother copying if you then delete it?

    Try using the shape collection to delete latest shape.

    activesheet.shapes(activesheet.shapes.count).delete
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    08-15-2014
    Location
    Slovakia
    MS-Off Ver
    7
    Posts
    6

    Re: Problem with selection of Text Box

    Thanks a lot. It somehow worked. I will use the programme for creating automatic reports so after the text box is pasted the sheet is saved as pdf. Then the programme will update the values and based on some of them new textbox
    will be selected and pasted and the sheet will be saved as pdf. and again and again...

    If you know, If there is actually possibility to move a text box from one sheet to another, without pasting it as a picture, but as a text box. I thought this will not be such a big deal (I am totally new to programming).

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Problem with selection of Text Box

    what code are you currently using to copy textbox?
    I assume the textbox is a shape and not a activex control

  7. #7
    Registered User
    Join Date
    08-15-2014
    Location
    Slovakia
    MS-Off Ver
    7
    Posts
    6

    Re: Problem with selection of Text Box

    Yes...you are right it is a shape. The code I am using

    For creating the textBox (for now I am just using dummy text)

    Sheets("zdroj").Shapes.AddTextbox(msoTextOrientationHorizontal, 50.5, 95.25, 203.25, 111).Select
       With Selection
            .ShapeRange(1).TextFrame2.TextRange.Characters.Text = "TOTO JE TEXT A"
            .Name = "nucem1"
       End With
    Then for deciding which text to paste

    If Sheets("vypocet").Range("B221") < 10 Then
           Sheets("zdroj").Shapes("nucem2").Copy
           Sheets("sablona").Range("D24").PasteSpecial
           'Sheets("sablona").Shapes("nucem2").Select
             'With Selection
              '.Name = "AktivObject1"
           'End With
    But as soon as it is pasted to the new sheet, I cannot select it and thus cannot delete it. I wanted to add something to Paste otions but couldnt find any code to keep formating and name of the copied shape.
    Last edited by phila7475; 08-15-2014 at 11:00 AM.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Problem with selection of Text Box

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Try these

    Sub AddTextbox()
    
        With Sheets("zdroj").Shapes.AddTextbox(msoTextOrientationHorizontal, 50.5, 95.25, 203.25, 111)
            .TextFrame2.TextRange.Characters.Text = "TOTO JE TEXT A"
            .Name = "nucem1"
        End With
    
    End Sub
    
    
    Sub CopyShape()
    
    If Sheets("vypocet").Range("B221") < 10 Then
        Sheets("zdroj").Shapes("nucem1").Copy
        With Sheets("sablona")
            .Paste
            With .Shapes("nucem1")
                .Name = "AktivObject1"
                .Left = .Parent.Range("D24").Left
                .Top = .Parent.Range("D24").Top
            End With
        End With
    End If
    
    End Sub

  9. #9
    Registered User
    Join Date
    08-15-2014
    Location
    Slovakia
    MS-Off Ver
    7
    Posts
    6

    Re: Problem with selection of Text Box

    Cool. I appreciate your quick help very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] list box and text box --drop down and selection problem
    By catchnanan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-18-2014, 01:25 PM
  2. Update Values problem and a Value Selection Problem----Please Help.
    By TrivialT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-29-2013, 02:43 PM
  3. [SOLVED] Swap out text in text box based on radio button selection
    By gordco in forum Excel General
    Replies: 2
    Last Post: 12-13-2012, 11:49 AM
  4. Easy problem for you, select rows after finding text string, delete selection
    By yeoman12 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2009, 09:08 PM
  5. Text selection macro problem
    By djstriker91 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-06-2005, 05:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1