Worksheet Area
Worksheet Area
(OP)
Hello !!
A couple of quick questions if I may relating to Excel 97
1) Does anyone know how to return the NT userid using Excel VBA?
2) I seem to remember that it is possible to restrict the area of a worksheet. So that you can not select outside the area you specify. Does anyone know the code/keyword for this action.
Thanks
Mike
A couple of quick questions if I may relating to Excel 97
1) Does anyone know how to return the NT userid using Excel VBA?
2) I seem to remember that it is possible to restrict the area of a worksheet. So that you can not select outside the area you specify. Does anyone know the code/keyword for this action.
Thanks
Mike





RE: Worksheet Area
Excel has a very good option for that already in it's menu. Under the Tools menu you can protect the worksheet so values in the cells can not be changed using the option Protection. However it's possible to specify cells which can always be changed by specifying the cell to be not locked. To do so select the cell, right click your mouse. Choose Format cells and select the Protection sheet. Deselect the option Locked before protecting your worksheet.
If you want to grant certain users access to the worksheet give them the password whit which they can unlock the sheet.
Now the answers to your questions...
1) Does anyone know how to return the NT userid using Excel VBA?
I think the interface of VBA is not suited for that. You are working within the office set of programs and therefore no function exists to get information from the Windows (NT) enviroment.
What you could do is use the following line to detect who is working with Excel, because I suppose that you want to lock parts of the workbook depending on the person who logged in.
Application.Username
This returns the name which you specified as username on the Generalk sheet under the Options in the Tools menu.
2) I seem to remember that it is possible to restrict the area of a worksheet. So that you can not select outside the area you specify. Does anyone know the code/keyword for this action.
I don't know if you can disallow some one to select certain cells which you don't want to. However with the method described above you can lock cells. To prevent them from even selecting the files just hide the empty rows and colums that you don't want to use before protecting the worksheet.
Good luck!
Jonathan
RE: Worksheet Area
Sheets("MySheet").Activate
Activesheet.ScrollArea="A1:H25"
Check out the command - I'm writing from memory.
RE: Worksheet Area
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Sub Main()
Dim sUser As String
Dim sComputer As String
Dim lpBuff As String * 1024
'Get the Login User Name
GetUserName lpBuff, Len(lpBuff)
sUser = Left$(lpBuff, (InStr(1, lpBuff, vbNullChar)) - 1)
lpBuff = ""
'Get the Computer Name
GetComputerName lpBuff, Len(lpBuff)
sComputer = Left$(lpBuff, (InStr(1, lpBuff, vbNullChar)) - 1)
lpBuff = ""
MsgBox "Login User: " & sUser & vbCrLf & _
"Computer Name: " & sComputer
End
End Sub
Hope this helps!
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Worksheet Area
I really found your reply very helpful. Do you know how to get the machine serial or ID number?
RE: Worksheet Area
Option Explicit
Declare Function GetVolumeInformation Lib "kernel32" _
Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long
Sub Main()
Dim lpRootPathName As String
Dim lpVolumeNameBuffer As String
Dim nVolumeNameSize As Long
Dim lpVolumeSerialNumber As Long
Dim lpMaximumComponentLength As Long
Dim lpFileSystemFlags As Long
Dim lpFileSystemNameBuffer As String
Dim nFileSystemNameSize As Long
Dim ReturnVal As Long
lpRootPathName = "C:\"
ReturnVal = GetVolumeInformation(lpRootPathName, _
lpVolumeNameBuffer, _
nVolumeNameSize, _
lpVolumeSerialNumber, _
lpMaximumComponentLength, _
lpFileSystemFlags, _
lpFileSystemNameBuffer, _
nFileSystemNameSize)
MsgBox "(" & lpVolumeSerialNumber & ")"
End
End Sub
Hope this helps...
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Worksheet Area
There is another way to get the login user, but it only works under NT/2000 because the username environment variable is not defined under 95/98. (Not sure about XP)
MsgBox Environ("USERNAME")
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Worksheet Area
Worksheets(2).ScrollArea = "A1:F10"
RE: Worksheet Area
To eliminate the restriction you will use:
Worksheets(2).ScrollArea = ""