+ Reply to Thread
Results 1 to 4 of 4

Macro to unhide sheets IF macro is enabled and hard drive serial # match list of HD#

Hybrid View

  1. #1
    Registered User
    Join Date
    11-22-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Macro to unhide sheets IF macro is enabled and hard drive serial # match list of HD#

    Hello there,
    i was looking all over the net to find a VBA code that will prevent my excel file from opening on different pc's but the ones in the office. But I could not find any.

    I have all my worksheets but one hidden.

    I need a VBA code to un-hide the sheets IF macros are enabled AND the serial number of the computer hard drive matches a list of serial numbers that are on the allow list.

    Thank You.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,586

    Re: Macro to unhide sheets IF macro is enabled and hard drive serial # match list of

    Found this code to get the serial number:

    Function GetPhysicalSerial() As Variant
    Dim obj As Object
    Dim WMI As Object
    Dim SNList() As String, i As Long, Count As Long
    Set WMI = GetObject("WinMgmts:")
    For Each obj In WMI.InstancesOf("Win32_PhysicalMedia")
        If obj.SerialNumber <> "" Then Count = Count + 1
    Next
    ReDim SNList(1 To Count, 1 To 1)
    i = 1
    For Each obj In WMI.InstancesOf("Win32_PhysicalMedia")
        SNList(i, 1) = obj.SerialNumber
        i = i + 1
        If i > Count Then Exit For
    Next
    GetPhysicalSerial = SNList
    End Function

    Paste into a VB code module, then enter =GetPhysicalSerial() anywhere on a worksheet. If you have more than one physical hard drive enter as an array function to return the serial number for each drive.


    Credit to:

    Doug Jenkins
    Interactive Design Services

    http://www.eng-tips.com/viewthread.cfm?qid=285948


    Regards
    Last edited by TMS; 11-24-2011 at 12:35 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro to unhide sheets IF macro is enabled and hard drive serial # match list of

    Sub snb()
     For Each dr In CreateObject("scripting.filesystemobject").drives
      MsgBox dr.driveletter & "_ " & dr.serialnumber
     Next
    End Sub



  4. #4
    Registered User
    Join Date
    11-22-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Macro to unhide sheets IF macro is enabled and hard drive serial # match list of

    Quote Originally Posted by snb View Post
    Sub snb()
     For Each dr In CreateObject("scripting.filesystemobject").drives
      MsgBox dr.driveletter & "_ " & dr.serialnumber
     Next
    End Sub
    snb what is your code doing ?
    How can I get it to work ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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