Home page:
[View without Frames]

=property("Last Author")
=property("Revision Number")
=property("Application Name")
=property("Last Print Date")
=property("Creation Date")
=Property("Last Save Time")
=property("Total Editing Time")
=property("Number of Pages")
=property("Number of Words")
=property("Number of Characters")
=property("Number of Bytes")
=property("Number of Lines")
=property("Number of Paragraphs")
=property("Number of Slides")
=property("Number of Notes")
=property("Number of Hidden Slides")
=property("Number of Multimedia Clips")
Function Property(aaa)
   'Excel Maintains: Title, Subject, Author, Keywords, Comments,
   '  Last Author, Application Name, Last Print Date, Creation Date,
   '  Last Save Time,
   '  Security, Category, Manager, Company
   'Some DejaNews threads: AN=393501043, AN=371066133
   'also see Chip Pearson's
  Property = ActiveWorkbook.BuiltinDocumentProperties(aaa)
End Function

Sub MarkProperties()
rw = 1      'XL95 maintains 13 of the 28 properties listed
For Each p In ActiveWorkbook.BuiltinDocumentProperties
    Cells(rw, 1) = p.Name   'Property() is a user function
    Cells(rw, 2).Formula = "=property(""" & p.Name & """)"
    rw = rw + 1
End Sub

Similar in VBA

Worksheets("SheetName").Protect Userinterfaceonly:=True

will enable you to programatically write to a worksheet sheet but won't
allow manual editing by a user.

System information

The following was posted by Norman Harker, 2001-09-25
Dim new_value As String
Dim txt As String
Dim i As Long
    i = 1
        new_value = Environ$(i)
        If Len(new_value) = 0 Then Exit Do
        txt = txt & new_value & vbCrLf
        i = i + 1
    txt = txt & "UserName = " & Application.UserName & vbCrLf
    txt = txt & "Active Printer = " & Application.ActivePrinter & vbCrLf
    txt = txt & "Default Path = " & Application.DefaultFilePath & vbCrLf
    txt = txt & "Library Path = " & Application.LibraryPath & vbCrLf
    txt = txt & "Operating System = " & Application.OperatingSystem _
                    & vbCrLf
    txt = txt & "Organisation Name = " & Application.OrganizationName & _
    txt = txt & "Start Up Path = " & Application.StartupPath & vbCrLf
    txt = txt & "Excel Version = " & Application.Version & vbCrLf
        ' val(application.Version) -- 11 = XL 2003, 10 = XP, 9 = 2000, 8 = 97
    txt = txt & "Current Workbook Path = " & _
        Application.ActiveWorkbook.Path & vbCrLf
    txt = txt & "Active Woorkbook Name = " & _
    MsgBox txt
End Sub
Microsoft Excel

PATH=C:\Program Files\Microsoft Office\Office\;C:\WINDOWS;
UserName = David McRitchie
Active Printer = Panasonic KX-P5400 v2013.112 on LPT1:
Default Path =
Operating System = Windows (32-bit) 4.10
Organisation Name =
Start Up Path = C:\WINDOWS\Application Data\Microsoft\Excel\XLSTART
Excel Version = 9.0
Current Workbook Path = C:\temp
Active Woorkbook Name = martin_hyperlinks.xls

The following was posted by Gary Brown, in same thread, and which he indicated was borrrowed HEAVILY from John Walkenbach's "Microsoft Excel 2000 Power Programming with VBA" (Strongly recommended!) -

Declare Function GetWindowsDirectoryA Lib "kernel32" _
  (ByVal lpbuffer As String, ByVal nsize As Long) As Long

Sub OpSysPath()
  Dim strPath As String, strDir As String
  strPath = Space(255)
  strDir = Left(strPath, _
    GetWindowsDirectoryA(strPath, Len(strPath)))
  MsgBox strDir
End Sub
Result for me:  C:\WINDOWS

See the above Environ("Username") Environ("Computername")

Userid from Tools, Options, General, User Name:

Function USRNameF()
  USRNameF = Application.UserName
End Function


an alternate approach for username

An approach the does not use VB is to create a name like "UserName", using Ctrl-F3, and assign it this definition: =GET.WORKSPACE(26)

Then in any cell just enter =UserName (without parens).  Jim Rech 2001-07-27 programming

Just a slight caution: If you use this method, just don't copy the cell with that formula to another sheet.  In Excel 97, this will cause a general protection fault and Excel will be closed (losing any unsaved work).  Newer versions may be more robust, but I haven't tested with them.  As long as you are cognizant of this, it shouldn't cause problems.  Tom Ogilvy

Obtain the Login Userid

Robert Bruce posted the following example 1998-11-30
Option Compare Database
Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If lngX <> 0 Then
        fOSUserName = Left$(strUserName, lngLen - 1)
        fOSUserName = ""
    End If
End Function
Formerly had cited a simpler one by Chris Rae but it was pointed out by Harlan Grove that it did not check the buffersize.


You are one of many distinguished visitors who have visited my site here or in a previous location  since this page was created on July 28, 2000.

Visit [my Excel home page]   [Index page]   [Excel Onsite Search]   [top of this page]

Please send your comments concerning this web page to: David McRitchie send email comments

Copyright © 1997 - 2004,  F. David McRitchie,  All Rights Reserved