AutoExec macro runing VBA function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
As I understand, AutoExec macro can only run VBA function not Sub. My be
somebody are able to perform how a such function looks like?
Thank' in advance
 
For the most part, the difference between a sub and function are small.

Sub:
Public Sub MyRoutine()
'code here
End Sub

Function:
Public Function MyRoutine() As String
'code here
MyRoutine = "SomeValue"
End Function

A function can return a value, a sub can't. The function doesn't have to
return a value if you don't want it to. If you have a sub that is doing what
you want, just change the first and last lines to say Function instead of
Sub. Also, change any Exit Sub statements to Exit Function. You will now be
able to call it from the macro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top