Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Hide Columns based on network username

I have the following code below located in the 'This Workbook'. This
code works great for hiding worksheets from certian users but I have a
situation now where I need to hide certain columns in "worksheet2" from
certain users. I am not sure if I have to add some sort of hide columns
code to
'worksheet2' or if I can somehow add it to the below code somwhere. I
am still pretty much a beginner, so any detailed answer on what exaclt
yI have to do would be very helpful. Thanks.


Private Sub Workbook_Open()
Application.ScreenUpdating = False
FrontpageFirst
On Error Resume Next
sStr = fOSUserName()
x = sStr
Select Case x
Case "chris"
Worksheets("worksheet1").Visible = True
Worksheets("worksheet2").Visible = True
Worksheets("worksheet3").Visible = True




Case Else
For i = 2 To Worksheets.Count
Worksheets(i).Visible = xlVeryHidden
Next
End Select
Worksheets(2).Activate
Worksheets(1).Visible = xlVeryHidden
Application.ScreenUpdating = False
Dim cb As CommandBar
CreateMenuBar NewCommandBar
End Sub

Sub FrontpageFirst()
Dim page As String
page = "Unauthorized"
On Error Resume Next
Worksheets(page).Visible = True
If Worksheets(1).Name = page Then
Worksheets(1).Activate
Else
Worksheets(page).Activate
If Err = 0 Then
ActiveSheet.Move befo=Worksheets(1)
Else
Worksheets.Add befo=Worksheets(1)
Worksheets(1).Name = page
End If
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
FrontpageFirst
For i = 2 To Worksheets.Count
Worksheets(i).Visible = xlVeryHidden
Next
Application.DisplayAlerts = True
ActiveWorkbook.Save
Application.DisplayAlerts = False
On Error Resume Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Hide Columns based on network username

Jim,

I could not get this to work, meaning they did not hide.
I tried a number of different things like

Case "chris"
Worksheets("worksheet1").Visible = True
Worksheets("worksheet2").Visible = True
Columns("A:C").Hidden = True
Worksheets("worksheet3").Visible = True

and I tried

Worksheets("worksheet1").Visible = True
Worksheets("worksheet2").Visible = True
Worksheets("worksheet3").Visible = True
With
Worksheets("worksheet2")
Columns("A:C").Hidden = True
End With

didn't work either

any suggestions?







Jim Jackson wrote:

Just add the line:
Columns("A:C").Hidden = True ' changing column names as required
--
Best wishes,

Jim


"Chris" wrote:

I have the following code below located in the 'This Workbook'. This
code works great for hiding worksheets from certian users but I have a
situation now where I need to hide certain columns in "worksheet2" from
certain users. I am not sure if I have to add some sort of hide columns
code to
'worksheet2' or if I can somehow add it to the below code somwhere. I
am still pretty much a beginner, so any detailed answer on what exaclt
yI have to do would be very helpful. Thanks.


Private Sub Workbook_Open()
Application.ScreenUpdating = False
FrontpageFirst
On Error Resume Next
sStr = fOSUserName()
x = sStr
Select Case x
Case "chris"
Worksheets("worksheet1").Visible = True
Worksheets("worksheet2").Visible = True
Worksheets("worksheet3").Visible = True




Case Else
For i = 2 To Worksheets.Count
Worksheets(i).Visible = xlVeryHidden
Next
End Select
Worksheets(2).Activate
Worksheets(1).Visible = xlVeryHidden
Application.ScreenUpdating = False
Dim cb As CommandBar
CreateMenuBar NewCommandBar
End Sub

Sub FrontpageFirst()
Dim page As String
page = "Unauthorized"
On Error Resume Next
Worksheets(page).Visible = True
If Worksheets(1).Name = page Then
Worksheets(1).Activate
Else
Worksheets(page).Activate
If Err = 0 Then
ActiveSheet.Move befo=Worksheets(1)
Else
Worksheets.Add befo=Worksheets(1)
Worksheets(1).Name = page
End If
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
FrontpageFirst
For i = 2 To Worksheets.Count
Worksheets(i).Visible = xlVeryHidden
Next
Application.DisplayAlerts = True
ActiveWorkbook.Save
Application.DisplayAlerts = False
On Error Resume Next
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Hide Columns based on network username

Thanks Jim, it worked!


Jim Thomlinson wrote:
That is using the application username which is different form the network
username. The OP wants Environ("UserName") which will return the network
logon user name. There are some cases where you need to use an API to get the
correct network user name but they are few and far between...
--
HTH...

Jim Thomlinson


"John Bundy" wrote:

I just used this and it works, you can adapt it to your code fairly easily.

If Application.UserName = "jmbundy" Then Sheets("Sheet1").Visible = False

--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.


"Chris" wrote:

I have the following code below located in the 'This Workbook'. This
code works great for hiding worksheets from certian users but I have a
situation now where I need to hide certain columns in "worksheet2" from
certain users. I am not sure if I have to add some sort of hide columns
code to
'worksheet2' or if I can somehow add it to the below code somwhere. I
am still pretty much a beginner, so any detailed answer on what exaclt
yI have to do would be very helpful. Thanks.


Private Sub Workbook_Open()
Application.ScreenUpdating = False
FrontpageFirst
On Error Resume Next
sStr = fOSUserName()
x = sStr
Select Case x
Case "chris"
Worksheets("worksheet1").Visible = True
Worksheets("worksheet2").Visible = True
Worksheets("worksheet3").Visible = True




Case Else
For i = 2 To Worksheets.Count
Worksheets(i).Visible = xlVeryHidden
Next
End Select
Worksheets(2).Activate
Worksheets(1).Visible = xlVeryHidden
Application.ScreenUpdating = False
Dim cb As CommandBar
CreateMenuBar NewCommandBar
End Sub

Sub FrontpageFirst()
Dim page As String
page = "Unauthorized"
On Error Resume Next
Worksheets(page).Visible = True
If Worksheets(1).Name = page Then
Worksheets(1).Activate
Else
Worksheets(page).Activate
If Err = 0 Then
ActiveSheet.Move befo=Worksheets(1)
Else
Worksheets.Add befo=Worksheets(1)
Worksheets(1).Name = page
End If
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
FrontpageFirst
For i = 2 To Worksheets.Count
Worksheets(i).Visible = xlVeryHidden
Next
Application.DisplayAlerts = True
ActiveWorkbook.Save
Application.DisplayAlerts = False
On Error Resume Next
End Sub



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
Network Username Adrian D. Bailey Excel Programming 2 January 20th 06 05:49 PM
Windows API to get network username of person with file open Paul Martin Excel Programming 7 December 2nd 05 04:31 PM
Windows API to get network username of person with file open Paul Martin Excel Programming 0 November 30th 05 05:23 AM
Looking for network-username with Excel macro Geert Nauta Excel Programming 1 October 4th 04 04:12 PM
Network detects if Windows Username is online Todd Huttenstine Excel Programming 0 July 9th 04 08:12 PM


All times are GMT +1. The time now is 12:54 AM.

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"