+ Reply to Thread
Results 1 to 3 of 3

problems with macro to automatically fill the username and macro to unhide sheets

Hybrid View

djtosh1 problems with macro to... 04-03-2015, 04:35 PM
Brendan_Floyde Re: problems with macro to... 04-03-2015, 05:41 PM
djtosh1 Re: problems with macro to... 04-07-2015, 07:14 AM
  1. #1
    Registered User
    Join Date
    04-29-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question problems with macro to automatically fill the username and macro to unhide sheets

    Hello, this is my first thread on the forum because i'm really out of ideas now.
    For my work, i'm trying to make our requests forms easier to feel.
    Therefore, i've created an excel workbook (which is protected by a password) with 7 sheets: the first one ("Global_data") is used to get the informations of the requestor and the employee if needed, the 6 others are the different requests form ("Material",Network","CN",...).

    These ones must stay hidden until all the fields in Global_data are filled.

    For that i've created the macro:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Sheets("Global_data").Range("G23").Value = 6 Then
    ActiveWorkbook.Unprotect Password:="****"
        Sheets("Material").Visible = True
        Sheets("Network").Visible = True
        Sheets("SAP REQUEST").Visible = True
        Sheets("CN Approval").Visible = True
        Sheets("PO Approval").Visible = True
        Sheets("VIM Approval").Visible = True
        Sheets("Material").Select
        ActiveSheet.Range("D22").Select
    ActiveWorkbook.Protect Password:="****", Structure:=True, Windows:=False
    End If
    End Sub
    But i've also added the following macro so that the user full name would automatically be filled in cell D14 in the sheet Global_data.

    Private Sub Workbook_open()
    Dim WSHnet As Object
    Dim Username As String
    Dim userdomain As String
    Dim objuser As Object
    Dim userfullname As String
    Sheets("Global_data").Select
    Set WSHnet = CreateObject("WScript.Network")
        Username = WSHnet.Username
        userdomain = WSHnet.userdomain
        Set objuser = GetObject("WinNT://" & userdomain & "/" & Username & ",user")
        userfullname = objuser.FullName
        MsgBox "User Full Name: " & vbCrLf & vbCrLf & userfullname, vbInformation, "User Full Name"
        Range("D14").Value = userfullname
    End Sub
    If i test my file on my pc, it seems working perfectly. also if i send it to some colleagues. Their name is filled in and the hidden sheets shown when all the required fields are filled.
    However, if i upload my file on our Intranet i always get this kind of error "error 1004 method range of object _worksheet failed".

    I guess the problem comes because i first do an even on workbook_open by filling cell D14 in the sheet Global_data while the second macro is a worksheet_change based on the same sheet. but i really don't know how to solve this?

    Can someone help me out please??

    Thanks a lot

  2. #2
    Forum Contributor
    Join Date
    01-14-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    240

    Re: problems with macro to automatically fill the username and macro to unhide sheets

    possibly in your Workbook_open

    
    Application.EnableEvents = false
    
    code
    
    
    Application.EnableEvents = true
    to try and stop the second event firing?
    Please consider adding a * if I helped.

  3. #3
    Registered User
    Join Date
    04-29-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: problems with macro to automatically fill the username and macro to unhide sheets

    Hi Brendan_Floyde,

    Thanks for your suggestion.
    Unfortunately, it doesn't help. I'm still getting error "Run-time error '1004':Activate method of worksheet class failed".

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Unhide sheets with username/password match entered
    By sporenta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2014, 03:16 PM
  2. [SOLVED] How to unhide/hide sheets with Macro?
    By jgomez in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-04-2013, 11:22 AM
  3. Restrict HIDE / UNHIDE sheets by Username
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-24-2012, 11:47 PM
  4. [SOLVED] Unhide Sheets Macro
    By Kazstankgardner in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-13-2012, 12:31 AM
  5. Macro to unhide sheets IF macro is enabled and hard drive serial # match list of HD#
    By nikolaikolev in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2011, 01:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1