Excell Visual Basic

After long time I had to do something with Visual Basic, so here is Hello World:

1. Open MS Excell
2. Open Visual Basic Editor (VBE)
Tools->Macro->Visual Basic Editor
3. In VBE open Module window
Insert->Module
4. Type following text:


Sub showMessage(msg)
MsgBox msg
End Sub
'
Function multiplyLine(line, n)
i = 1
msg = "1. " + line
Do While (i < n)
i = i + 1
msg = msg + Chr(10) + CStr(i) + ". " + line
Loop
multiplyLine = msg
End Function
'
Sub showMultipleMessages()
iNum = InputBox("Multiple Messages Input", "How many messages would you like")
n = 0 + iNum 'conversion
m = "Multiple messages:" + vbLf + multiplyLine("Hello", n)
showMessage (m)
End Sub

5. Click Run or press Alt-R

This entry was posted in workday. Bookmark the permalink.

Leave a Reply