MrExcel Publishing
Your One Stop for Excel Tips & Solutions

inserting vbLf (line feed)

Posted by Robert Simms on October 19, 2001 6:09 AM

A friend has a lap top computer with no numeric keypad "Enter" key. This seems to make it impossible to force line breaks with Alt+Enter (which will enable user-controled line breaks in line wrapping formatted cells).

Excel provides a sample of what might be done... under Toolbars/Customize/Commands in the "Insert" category there are buttons/commands to insert single characters. These work in or out of formula bar editing mode.

I tried recording a macro wherein I entered a line break in a cell. The macro just sets the value of the cell to a string, using string concatenation and the "vbLf" constant.

So, the question is: with a macro, can anyone find out how to mimic the user typing any key or key combination, in or out of formula bar editing mode? Or how to paste a character at the cursor position in the formula bar.

Posted by Robert Simms on October 20, 2001 4:25 AM

Well, having Excel 98 (Mac), last night I found the answer for Excel 97 but can't test it until I get to my friends PC laptop.

The macro command to enter a line feed should be (according to the SendKeys Method help):


The SendKeys command simulates key presses, and the % sign corresponds to the Alt modifier. I guess MS didn't want to take the time to map all the key modifiers out on the Mac platform before they published Excel 98, so when you try to use this on a Mac, you get an error message that this command isn't supported there.

Hopefully this has been corrected in Excel 2001... shall see when I get the chance.

Posted by Robert Simms on October 23, 2001 6:01 AM

Re: line feed

Installment 3:
Excel 2001 on the Mac still doesn't support the SendKeys method.

Application.SendKeys("%{ENTER}") didn't insert a line break while formula bar editing was in progress.

However, Alt+Return on the PC Laptop did work, which is good, since there was no Enter key equivalent.

This still doesn't answer the question of How can a Macro duplicate the behaviour of the Insert Character buttons offered in Toolbar Customization.