Consulting

Results 1 to 7 of 7

Thread: Having a problem debugging using SendKeys

  1. #1
    VBAX Regular
    Joined
    Mar 2012
    Posts
    37
    Location

    Having a problem debugging using SendKeys

    Hopefully this is something real simple that I am overlooking.

    I need to eliminate a paragraph marker which is the last character at the end of my text in a cell within excel. In order to keep my formatting of text within a cell (different colors of text within the same string in the cell), i believe i must use SendKeys (I stand to be corrected on this). All other solutions I have tried to eliminate the end marker makes me lose my different colors in the paragraph I have formatted the text with. The SendKeys approach solves this problem. The SendKeys code I am using to eliminate the last character is:

    Code:
    Application.SendKeys "{F2}"
    Application.SendKeys "{Backspace}"
    Application.SendKeys "{Enter}"

    Problem is, I am having to debug and when I come across these sendkey
    strokes in F8 step mode, it sends the strokes to the vbe and ceases processing them in the spreadsheet. How do I keep the sendkeys working on the spreadsheet while i am stepping through vbe debugging? thx

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    If you know the last character should be removed perhaps just
    activecell.Characters(activecell.Characters.Count, 1).Text = ""
    Last edited by Aussiebear; 04-12-2023 at 11:55 PM. Reason: Adjusted the code tags
    Be as you wish to seem

  3. #3
    VBAX Regular
    Joined
    Mar 2012
    Posts
    37
    Location
    Quote Originally Posted by Aflatoon
    If you know the last character should be removed perhaps just
    [vba]activecell.Characters(activecell.Characters.Count, 1).Text = ""[/vba]
    Thanks, when I do this, I lose all my different color formatting within one string of text. Picture a string of 80 words in one paragraph. 20 are colored red, 20 are green, 20 are blue, and 20 are gold. I want to preserve these colors in one string. When I do what you suggest, the cell reverts to the color of the color assignment of the cell.

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Which version of Excel? Formatting was preserved in a quick test in 2013.
    Be as you wish to seem

  5. #5
    VBAX Regular
    Joined
    Mar 2012
    Posts
    37
    Location
    2010

  6. #6
    VBAX Regular
    Joined
    Mar 2012
    Posts
    37
    Location
    Also, I tried putting this in my procedure, it doesn't work, does not take the last character out of my string.

  7. #7
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Just tested in 2010 and it removed the final character and left formatting intact. How exactly did you implement it in your existing code?

    For info, cross-post here.
    Last edited by Aflatoon; 04-11-2013 at 06:25 AM.
    Be as you wish to seem

Posting Permissions

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