PDA

View Full Version : Having a problem debugging using SendKeys



pglufkin
04-10-2013, 02:08 PM
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

Aflatoon
04-10-2013, 02:41 PM
If you know the last character should be removed perhaps just

activecell.Characters(activecell.Characters.Count, 1).Text = ""

pglufkin
04-10-2013, 02:48 PM
If you know the last character should be removed perhaps just
activecell.Characters(activecell.Characters.Count, 1).Text = ""

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.

Aflatoon
04-11-2013, 12:22 AM
Which version of Excel? Formatting was preserved in a quick test in 2013.

pglufkin
04-11-2013, 05:12 AM
2010

pglufkin
04-11-2013, 05:18 AM
Also, I tried putting this in my procedure, it doesn't work, does not take the last character out of my string.

Aflatoon
04-11-2013, 05:25 AM
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 (http://www.mrexcel.com/forum/excel-questions/696309-having-problem-debugging-using-sendkeys.html).