Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 64
Default Enable Command Button base on UserName

I have a Command Button on a worksheet that I only want to display if a
specified User Opens the workbook.

I have the following code:

(in a UserName module)
=================
' By Chris Rae, 14/6/99, 3/9/00.
Option Explicit
' This is used by GetUserName() to find the current user's
' name from the API
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Function GetUserName() As String
Dim lpBuff As String * 25
Dim txtName As String

Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
txtName = lpBuff
MsgBox ("Welcome to the NEW Pricing Tool " & (lpBuff)), vbOKOnly


End Function

====================
How would I modify the code to enable the cmdQC button? I was thinking
something like the following ...

(In the code for the worksheet)
Sub Auto_Open()
GetUserName
If lpBuff = 'Person's UserName' then cmdQC.visible.True

End Sub

Many thanks (in advance) for your assistance.

Shane


  #2   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,123
Default Enable Command Button base on UserName

Try this

If Environ("UserName") = "???" Then
ActiveSheet.Shapes("CommandButton1").Visible = True
Else
ActiveSheet.Shapes("CommandButton1").Visible = False
End If



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Doctorjones_md" wrote in message ...
I have a Command Button on a worksheet that I only want to display if a
specified User Opens the workbook.

I have the following code:

(in a UserName module)
=================
' By Chris Rae, 14/6/99, 3/9/00.
Option Explicit
' This is used by GetUserName() to find the current user's
' name from the API
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Function GetUserName() As String
Dim lpBuff As String * 25
Dim txtName As String

Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
txtName = lpBuff
MsgBox ("Welcome to the NEW Pricing Tool " & (lpBuff)), vbOKOnly


End Function

====================
How would I modify the code to enable the cmdQC button? I was thinking
something like the following ...

(In the code for the worksheet)
Sub Auto_Open()
GetUserName
If lpBuff = 'Person's UserName' then cmdQC.visible.True

End Sub

Many thanks (in advance) for your assistance.

Shane


  #3   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,123
Default Enable Command Button base on UserName

Change ActiveSheet to your sheet name

Sheets("???")

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Ron de Bruin" wrote in message ...
Try this

If Environ("UserName") = "???" Then
ActiveSheet.Shapes("CommandButton1").Visible = True
Else
ActiveSheet.Shapes("CommandButton1").Visible = False
End If



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Doctorjones_md" wrote in message ...
I have a Command Button on a worksheet that I only want to display if a
specified User Opens the workbook.

I have the following code:

(in a UserName module)
=================
' By Chris Rae, 14/6/99, 3/9/00.
Option Explicit
' This is used by GetUserName() to find the current user's
' name from the API
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Function GetUserName() As String
Dim lpBuff As String * 25
Dim txtName As String

Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
txtName = lpBuff
MsgBox ("Welcome to the NEW Pricing Tool " & (lpBuff)), vbOKOnly


End Function

====================
How would I modify the code to enable the cmdQC button? I was thinking
something like the following ...

(In the code for the worksheet)
Sub Auto_Open()
GetUserName
If lpBuff = 'Person's UserName' then cmdQC.visible.True

End Sub

Many thanks (in advance) for your assistance.

Shane


  #4   Report Post  
Posted to microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6,953
Default Enable Command Button base on UserName

Sub Auto_Open()
Dim sUserName as String
sUserName = GetUserName()
With worksheets("Sheet1")
If lcase(sUserName) = lcase("Person's UserName") then
.OleObjects("cmdQC").visible.True
else
.OleObjects("cmdQc").Visible = False
End it
End With
End Sub

assuming cmdQc is the name of the control

--
regards,
Tom Ogilvy


"Doctorjones_md" wrote:

I have a Command Button on a worksheet that I only want to display if a
specified User Opens the workbook.

I have the following code:

(in a UserName module)
=================
' By Chris Rae, 14/6/99, 3/9/00.
Option Explicit
' This is used by GetUserName() to find the current user's
' name from the API
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Function GetUserName() As String
Dim lpBuff As String * 25
Dim txtName As String

Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
txtName = lpBuff
MsgBox ("Welcome to the NEW Pricing Tool " & (lpBuff)), vbOKOnly


End Function

====================
How would I modify the code to enable the cmdQC button? I was thinking
something like the following ...

(In the code for the worksheet)
Sub Auto_Open()
GetUserName
If lpBuff = 'Person's UserName' then cmdQC.visible.True

End Sub

Many thanks (in advance) for your assistance.

Shane



  #5   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 64
Default Enable Command Button base on UserName

Ron,

I tried your code -- is this supposed to be in a module, or in the code for
the worksheet? Is it something like this ...

Private Sub QC()

If Environ("UserName") = "???" Then
ActiveSheet.MySheet("cmd").Visible = True
Else
ActiveSheet.MySheet("CommandButton1").Visible = False
End If

End Sub
================================================== ======
"Ron de Bruin" wrote in message
...
Try this

If Environ("UserName") = "???" Then
ActiveSheet.Shapes("CommandButton1").Visible = True
Else
ActiveSheet.Shapes("CommandButton1").Visible = False
End If



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Doctorjones_md" wrote in message
...
I have a Command Button on a worksheet that I only want to display if a
specified User Opens the workbook.

I have the following code:

(in a UserName module)
=================
' By Chris Rae, 14/6/99, 3/9/00.
Option Explicit
' This is used by GetUserName() to find the current user's
' name from the API
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Function GetUserName() As String
Dim lpBuff As String * 25
Dim txtName As String

Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
txtName = lpBuff
MsgBox ("Welcome to the NEW Pricing Tool " & (lpBuff)), vbOKOnly


End Function

====================
How would I modify the code to enable the cmdQC button? I was thinking
something like the following ...

(In the code for the worksheet)
Sub Auto_Open()
GetUserName
If lpBuff = 'Person's UserName' then cmdQC.visible.True

End Sub

Many thanks (in advance) for your assistance.

Shane




  #6   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,123
Default Enable Command Button base on UserName

In your example you use
Sub Auto_Open()


You must copy this in a normal module
See
http://www.cpearson.com/excel/events.htm

Use this for user "ron" with the button on "Sheet1"
It will run automatic if you open the workbook

Sub Auto_Open()
If Environ("UserName") = "Ron" Then
Sheets("Sheet1").Shapes("CommandButton1").Visible = True
Else
Sheets("Sheet1").Shapes("CommandButton1").Visible = False
End If
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Doctorjones_md" wrote in message ...
Ron,

I tried your code -- is this supposed to be in a module, or in the code for
the worksheet? Is it something like this ...

Private Sub QC()

If Environ("UserName") = "???" Then
ActiveSheet.MySheet("cmd").Visible = True
Else
ActiveSheet.MySheet("CommandButton1").Visible = False
End If

End Sub
================================================== ======
"Ron de Bruin" wrote in message
...
Try this

If Environ("UserName") = "???" Then
ActiveSheet.Shapes("CommandButton1").Visible = True
Else
ActiveSheet.Shapes("CommandButton1").Visible = False
End If



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Doctorjones_md" wrote in message
...
I have a Command Button on a worksheet that I only want to display if a
specified User Opens the workbook.

I have the following code:

(in a UserName module)
=================
' By Chris Rae, 14/6/99, 3/9/00.
Option Explicit
' This is used by GetUserName() to find the current user's
' name from the API
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Function GetUserName() As String
Dim lpBuff As String * 25
Dim txtName As String

Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
txtName = lpBuff
MsgBox ("Welcome to the NEW Pricing Tool " & (lpBuff)), vbOKOnly


End Function

====================
How would I modify the code to enable the cmdQC button? I was thinking
something like the following ...

(In the code for the worksheet)
Sub Auto_Open()
GetUserName
If lpBuff = 'Person's UserName' then cmdQC.visible.True

End Sub

Many thanks (in advance) for your assistance.

Shane


  #7   Report Post  
Posted to microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default Enable Command Button base on UserName

Tom,

My apologies for not posting back sooner -- the code you provided did the
trick PERFECTLY! Thanks a bunch -- have an awesome weekend.

Shane
=============
"Tom Ogilvy" wrote in message
...
Sub Auto_Open()
Dim sUserName as String
sUserName = GetUserName()
With worksheets("Sheet1")
If lcase(sUserName) = lcase("Person's UserName") then
.OleObjects("cmdQC").visible.True
else
.OleObjects("cmdQc").Visible = False
End it
End With
End Sub

assuming cmdQc is the name of the control

--
regards,
Tom Ogilvy


"Doctorjones_md" wrote:

I have a Command Button on a worksheet that I only want to display if a
specified User Opens the workbook.

I have the following code:

(in a UserName module)
=================
' By Chris Rae, 14/6/99, 3/9/00.
Option Explicit
' This is used by GetUserName() to find the current user's
' name from the API
Declare Function Get_User_Name Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Function GetUserName() As String
Dim lpBuff As String * 25
Dim txtName As String

Get_User_Name lpBuff, 25
GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
txtName = lpBuff
MsgBox ("Welcome to the NEW Pricing Tool " & (lpBuff)), vbOKOnly


End Function

====================
How would I modify the code to enable the cmdQC button? I was thinking
something like the following ...

(In the code for the worksheet)
Sub Auto_Open()
GetUserName
If lpBuff = 'Person's UserName' then cmdQC.visible.True

End Sub

Many thanks (in advance) for your assistance.

Shane





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable Command Button base on UserName Doctorjones_md Excel Discussion (Misc queries) 6 April 20th 07 07:16 PM
Enable Command Button base on UserName Doctorjones_md Excel Worksheet Functions 6 April 20th 07 07:16 PM
Enable Command Button After Entering Text mikeg710 New Users to Excel 1 March 29th 07 04:12 PM
command button Hellboy Excel Discussion (Misc queries) 0 November 3rd 05 03:51 PM
Can the Combo Box move and size with cells radio button be enable Tom Cote Excel Worksheet Functions 0 September 5th 05 09:27 PM


All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"