Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
Por Guinardelli23
#65298
Boa noite, estou utilizando um código para ler o "mac aderess" da máquina e permitir ou não o uso da planilha. A questão é que em notebooks com acesso wifi e ethernet, temos 2 registros de MAC e não consigo identificar os 2 ao mesmo tempo.

Se eu cadastrar o MAC do wifi o usuário não consegue abrir a planilha conectado na rede.

Se eu cadastrar o MAC da ethernet o usuário não consegue abrir a planilha e usar o wifi.
Código: Selecionar todos
Private Sub Workbook_Open()

'-----VERIFICAÇÃO DO MAC ADERESS---------------------------------------------------------------------------------------------------------

    Dim sComputer As String
    Dim MeuMAC As String
    Dim oWMIService As Object
    Dim oAdapters As Object
    Dim oAdapter As Object
    Dim sRet As String

    sComputer = "."
    sRet = ""
    Set oWMIService = GetObject("winmgmts:" & "!\\" & sComputer & "\root\cimv2")
    Set oAdapters = oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    For Each oAdapter In oAdapters
        If Len(sRet) > 0 Then
            sRet = sRet + "/" + oAdapter.MACAddress
        Else
            sRet = oAdapter.MACAddress
        End If
    Next oAdapter

    GetMACAddr = sRet
Código: Selecionar todos
MeuMAC1 = "D8:BB:C1:04:EC:F3"       'Guilherme PC Projetos01
MeuMAC2 = "8C:A9:82:FD:55:61"      'Guilherme Notebook
Código: Selecionar todos
If MeuMAC1 = GetMACAddr Then
                                    'MsgBox "Acesso autorizado!"
    Else
    If MeuMAC2 = GetMACAddr Then
                                    MsgBox "Acesso autorizado!"
Código: Selecionar todos
Else
       MsgBox "Você não está autorizado a utilizar esta planilha!"
       ActiveWorkbook.Close SaveChanges = False                         'Comando para fechar a planilha sem salvar
           
    End If
    End If

Algum dica de como resolver?
Por osvaldomp
#65302
Código: Selecionar todos
 If Address1 = "AAA" And Address2 = "BBB" Then
  MsgBox "autorizado"
 Else: MsgBox "não autorizado"
 End If
#65316
Obrigado por responder Osvaldo.

Utilizando a fórmula conforme você disse, eu consigo utilizar a planilha com o cabo ethernet e sem wi-fi, ou com o wi-fi e sem o cabo ethernet. A planilha não funciona quando estou conectado no wi-fi e ethernet.

Veja que usando o comando GETMAC, tenho 2 valores:

Imagem
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord