Nanobrain91
Nanobrain91

Reputation: 55

VBA to think that certain key was pressed

I am wondering if there is a way to make VBA think that certain key was pressed? To give an example, let's say that i want Excel to automatically start on a new line inside a cell ( Alt + Enter keys ) after i wrote a text of specific length.

Is it possible to make Excel think that i just pressed those keys even when i did not?

Thank you for any suggestions.

Upvotes: 0

Views: 119

Answers (2)

FreeMan
FreeMan

Reputation: 5687

If you're inserting text into a cell, you can simply include vbCrLf, like this:

Sub foo(ByVal theCell As Range)
  theCell.Value = "First line of text." & vbCrLf & "Second line of text."
End Sub

Upvotes: 2

Anthony
Anthony

Reputation: 552

Use Application.SendKeys. For example: Application.SendKeys("%fx")

This command will quit Excel

Upvotes: 0

Related Questions