×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Writing VBA Excel functions

Writing VBA Excel functions

Writing VBA Excel functions

(OP)
I am very new to VBA stuff. I have two functions that I am trying to write. I would like them to work for Excel 2007, 2010 and finally 2000 if possible.

1. I would like to open a worksheet and have a function returns the name of the user/machine who last saved the file. My attempt:
Function LastAuthor()
LastAuthor = ThisWorkbook.BuiltinDocumentProperties("Last Author")
End Function

Cell formula: =LastAuthor()

2. I would like to open a worksheet and have a function returns the name of the current user/machine. My attempt:
Function CurrentUser()
CurrentUser = ActiveWorkbook.UserStatus
End Function

Cell formula: =CurrentUser()

Thanks, Steve

RE: Writing VBA Excel functions

(OP)
Doug,
I was having a hard time because the functions were working on a Excel 2010 machine and a 2007 machine but not on my Excel 2007 computer. It turns out that my Excel Options/Trust Center/Macro Settings were set to "Enable all macros" and the other machines were set to "Disable all macros with notification".

So when I changed the setting on my computer, it worked! I had to click on the notification to enable the macros.

I am not sure why this makes a difference. Is there something else that I should do to make these 2 functions work for either setting?

RE: Writing VBA Excel functions

Steve - that seems very strange, are you sure the setting was not "Disable all macros"?

You can set a directory (and all sub-directories underneath it) as a "trusted location", then you don't have to click anything to get the macros to work (as long as they are saved to the trusted location).

The other thing to watch for is that the file is not saved as an xlsx, which will loose any attached VBA. The macros in any file saved as .xls, .xlsb, or .xlsm should work, as long as macros are enabled.

On other people's machines there is nothing you can do to guarantee that macros will run. If the computer is set to disable all macros, or if the user does not enable them when prompted, then they won't work.

Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/

RE: Writing VBA Excel functions

(OP)
Doug,
I am not sure why the "Enable all macros" doesn't work on my 2007. So I kept the "Disable all macros with notification" setting because it works and added a "trusted location" as you suggested. Perfect! Thanks

I am using the .xls format to keep it compatible with 2000.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close