[RESOLVIDO] Erro atualização de código para 64bits

cy_rangel

29-01-2016 22:46:15

Caros,

Boa-noite.

Tenho uma macro com a seguinte função dentro de um modulo:

Código: Selecionar todos

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
    lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As _
    Long
Ao iniciar a planilha aparece a mensagem em anexo, dizendo que o código do projeto deve ser atualizado para uso em sistemas 64bits. Alguém sabe me dizer como atualizo isso??? e se depois de atualizar em sistema de 64bits eu posso rodar a mesma macro sem dar erro em sistema como por exemplo de 32bits?

Desde já agradeço.

Att,
Cy Rangel

Mikel Silveira Fraga

29-01-2016 23:44:43

Cy, boa noite mais uma vez.

Tenho visto que estas conseguindo evoluir bem no teu projeto. Muito bom.

Bem, na verdade é totalmente possível realizar uma estrutura que reconheça as diversas situações. Segue o código que você vai precisar substituir:

Código: Selecionar todos

#If VBA7 Then 'Declaração de API´s para versões do MS Office 2010+.
    
    #If Win64 Then 'Declaração para as versões 64 bits.
            
        Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
        (ByVal hwnd As LongLong, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
        lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As LongLong) As _
        LongLong
            
    #Else 'Declaração para as versões 32 bits.
        
        Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
        (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
        lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As LongPtr) As _
        LongPtr
        
    #End If
    
#ElseIf VBA6 Then 'Declaração de API´s para versões do MS Office 2007-.
    
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
    lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As _
    Long

#End If
Dessa maneira, ele vai reconhecer a versão do VBA7 (existente nas versões do Office 2010, ou superiores, e dividido em 64 bits e 32 bits), como também nas versões do VBA6 (existente nas versões do Office 2007, ou inferiores).

Faça o teste e nos retorne.

Um excelente final de semana. Forte abraço.

cy_rangel

30-01-2016 01:50:18

Obrigada Mikel, funcionou perfeitamente...

Essa variação acontece porque no meu trab. o office é mais antigo e em casa já é o 2013, mas que bom que assim funciona nos dois....

Ps.: a evolução do projeto é graças a vocês que estão sempre dispostos a ajudar... Sou muito grata por isso :)

Att,
Cy Rangel.

esresende

27-03-2016 22:03:44

Boa Noite. Estou com esse mesmo problema, baixei aversão aqui do site http://www.tomasvasquez.com.br/blog/mic ... so-a-passo. Estou engatinhando em VBA e não estou conseguindo resolver. Quem ajudar agradeço.

Abras

Mikel Silveira Fraga

28-03-2016 12:38:15

Resende, bom dia.

Qual erro esta ocorrendo exatamente pra você? Pode postar o bloco de código onde o mesmo ocorre?

Ficamos no aguardo.

esresende

03-04-2016 20:34:36

Boa tarde. A mensagem é exatamente a mesma, com o erro acontecendo no mesmo local. O Código está no link. Outra pergunta, ao baixar o arquivo do link citado anteriormente, vieram dois arquivos, MdC_FrontEnd ListView e ModeloCadastro_Dados, esse último ao executar dois cliques nada acontece. Qual a necessidade desses arquivos? para que serve esse primeiro?

Obrigado

Mikel Silveira Fraga

04-04-2016 14:18:24

Resende, bom dia. Tudo bem?

Então cara, se a mensagem é a mesma, é necessário que você pegue o mesmo código que passei acima e o adapte, corrigindo o erro.

Sobre os arquivos que vieram no arquivo compactado, os dois são necessários para que a ferramenta funcione. Eles funcionam da seguinte forma:
- MdC_FrontEnd ListView: nesta planilha, você vai ter acesso aos formulários, onde poderá cadastrar, pesquisar ou excluir os registros;
- ModeloCadastro_Dados: já nesta planilha, você vai localizar os registros armazenados/gravados.

Esse foi um modelo desenvolvido, trabalhando com as informações separadamente.

Espero ter conseguido esclarecer suas dúvidas.

Forte abraço e excelente semana.

Júnior

28-07-2016 03:30:55

Boa Noite,
Como ainda estou iniciando no excell (VBA), estou tendo dificuldade para resolver o mesmo problema e gostaria de uma ajuda. Ao iniciar a planilha aparece uma mensagem dizendo que o código do projeto deve ser atualizado para uso em sistemas 64bits. Eu preciso atualizar para um sistema de 64 bits, porém, de forma que ele ainda rode em um sistema de 32 bits. Isto é possível?
Tenho a seguinte função dentro de um módulo:

Option Explicit

Private Declare Function GetForegroundWindow Lib "user32" () As Long

Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" ( _
ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)

Declare Function SetWindowsHookEx Lib _
"user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, _
ByVal hmod As Long, ByVal dwThreadId As Long) As Long

Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long

Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Type POINTAPI
X As Long
Y As Long
End Type

Type MSLLHOOKSTRUCT
pt As POINTAPI
mouseData As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type

Const HC_ACTION = 0
Const WH_MOUSE_LL = 14
Const WM_MOUSEWHEEL = &H20A

Dim hhkLowLevelMouse, lngInitialColor As Long
Dim udtlParamStuct As MSLLHOOKSTRUCT
Public intTopIndex As Integer

Function GetHookStruct(ByVal lParam As Long) As MSLLHOOKSTRUCT

CopyMemory VarPtr(udtlParamStuct), lParam, LenB(udtlParamStuct)

GetHookStruct = udtlParamStuct

End Function

Function LowLevelMouseProc _
(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

On Error Resume Next

If (nCode = HC_ACTION) Then

If wParam = WM_MOUSEWHEEL Then

LowLevelMouseProc = True

'ATENÇÃO: Troque o nome do seu Userform
With frmCadastro

'ROLAR PARA CIMA
If GetHookStruct(lParam).mouseData > 0 Then
.ScrollTop = intTopIndex - 10
intTopIndex = .ScrollTop
Else
'ROLAR PARA BAIXO
.ScrollTop = intTopIndex + 10
intTopIndex = .ScrollTop
End If

End With

End If

Exit Function

End If

UnhookWindowsHookEx hhkLowLevelMouse
LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)

End Function

Sub Hook_Mouse()
If hhkLowLevelMouse <> 0 Then
UnhookWindowsHookEx hhkLowLevelMouse
End If

hhkLowLevelMouse = SetWindowsHookEx _
(WH_MOUSE_LL, AddressOf LowLevelMouseProc, Application.Hinstance, 0)

End Sub

Sub UnHook_Mouse()

If hhkLowLevelMouse <> 0 Then UnhookWindowsHookEx hhkLowLevelMouse

End Sub

Sub Apagar_Dados()
'
' Apagar_Dados Macro
'

'
Range("O5:X5").Select
Selection.ClearContents
Range("O9:X2008").Select
Selection.ClearContents
Range("R5").Select
End Sub
Sub Consulta_Avancada()
'
' Consulta_Avancada Macro
'

'
Range("C8:L2008").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range _
("O4:X5"), CopyToRange:=Range("Plan1!Extract"), Unique:=False

MsgBox "Consulta Efetuada com Sucesso!", vbInformation + vbOKOnly, "Consulta"

End Sub



Desde já,
Muito Obrigado!!!

alves

12-10-2016 21:13:28

Mikel.
Estou como o mesmo problema citado acima.

Aonde coloco esse código que você informou? Em algum módulo?

Mikel Silveira Fraga

12-10-2016 23:45:43

Alves, boa noite e seja bem vindo ao fórum.

Não conheço o seu modelo, mas geralmente, para esse tipo de código, é recomendado que seja colocado em módulos.

Teste e nos retorne. Abraços.

RODRIGOOC

28-10-2016 19:53:21

Re: [RESOLVIDO] Erro atualização de código para 64bits
Mensagempor Mikel Silveira Fraga » Qua Out 12, 2016 8:45 pm

Alves, boa noite e seja bem vindo ao fórum.

Não conheço o seu modelo, mas geralmente, para esse tipo de código, é recomendado que seja colocado em módulos.

Teste e nos retorne. Abraços.
Boa tarde, Mikel Silveira Fraga e demais colegas. Sou novo no fórum em tenho aprendido muito com o fórum.
Fiz uma pesquisa no tópico "Botao Maximizar e Minimizar"(viewtopic.php?t=758#p4324), verifiquei que era necessário realizar a compatibilidade com o Excel 64 bits.
Então localizei esse tópico. Realizei as adaptações que acho que seriam necessárias.

Código: Selecionar todos

#If VBA7 Then 'Declaração de API´s para versões do MS Office 2010+.
    
    #If Win64 Then 'Declaração para as versões 64 bits.
            
        Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
        (ByVal hwnd As LongLong, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
        lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As LongLong) As _
        LongLong
        
        Option Explicit
        
        Private Declare PtrSafe Function GetForegroundWindow Lib "user32" () As Long
        
        Declare PtrSafe Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" ( _
            ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        
        Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
            ByVal lpClassName As String, ByVal lpWindowName As String) As Long
            
        Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
        (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
        
        Declare PtrSafe Function SetWindowsHookEx Lib _
        "user32" Alias "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpfn As LongPtr, _
        ByVal hmod As LongPtr, ByVal dwThreadId As LongPtr) As Long
        
        Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
        ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
        
        Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
        
        Type POINTAPI
          X As LongPtr
          Y As LongPtr
        End Type
        
        Type MSLLHOOKSTRUCT
            pt As POINTAPI
            mouseData As LongPtr
            flags As LongPtr
            time As LongPtr
            dwExtraInfo As LongPtr
        End Type
        
        Const HC_ACTION = 0
        Const WH_MOUSE_LL = 14
        Const WM_MOUSEWHEEL = &H20A
        
        Dim hhkLowLevelMouse, lngInitialColor As LongPtr
        Dim udtlParamStuct As MSLLHOOKSTRUCT
        Public intTopIndex As Integer
        
        
        Function GetHookStruct(ByVal lParam As LongPtr) As MSLLHOOKSTRUCT
        
           CopyMemory VarPtr(udtlParamStuct), lParam, LenB(udtlParamStuct)
            
           GetHookStruct = udtlParamStuct
            
        End Function
        
        Function LowLevelMouseProc _
        (ByVal nCode As LongPtr, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
        
            On Error Resume Next
        
            If (nCode = HC_ACTION) Then
                
                If wParam = WM_MOUSEWHEEL Then
                    
                    LowLevelMouseProc = True
                    
                    'ATENÇÃO: Troque o nome do seu Userform
                    With UserForm1
                        
                        'ROLAR PARA CIMA
                        If GetHookStruct(lParam).mouseData > 0 Then
                            .ScrollTop = intTopIndex - 10
                            intTopIndex = .ScrollTop
                        Else
                        'ROLAR PARA BAIXO
                            .ScrollTop = intTopIndex + 10
                            intTopIndex = .ScrollTop
                        End If
                        
                    End With
                    
                End If
                
                Exit Function
                
            End If
        
            UnhookWindowsHookEx hhkLowLevelMouse
            LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
        End Function
        
        Sub Hook_Mouse()
            If hhkLowLevelMouse <> 0 Then
                UnhookWindowsHookEx hhkLowLevelMouse
            End If
                
            hhkLowLevelMouse = SetWindowsHookEx _
            (WH_MOUSE_LL, AddressOf LowLevelMouseProc, Application.Hinstance, 0)
        
        End Sub
        
        Sub UnHook_Mouse()
        
            If hhkLowLevelMouse <> 0 Then UnhookWindowsHookEx hhkLowLevelMouse
            
        End Sub
        
            
    #Else 'Declaração para as versões 32 bits.
        
        Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
        (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
        lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As LongPtr) As _
        LongPtr
        
        Option Explicit
     
        Private Declare Function GetForegroundWindow Lib "user32" () As Long
        
        Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" ( _
            ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        
        Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
            ByVal lpClassName As String, ByVal lpWindowName As String) As Long
            
        Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
        (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
        
        Declare Function SetWindowsHookEx Lib _
        "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, _
        ByVal hmod As Long, ByVal dwThreadId As Long) As Long
        
        Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
        ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
        
        Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
        
        Type POINTAPI
          X As Long
          Y As Long
        End Type
        
        Type MSLLHOOKSTRUCT
            pt As POINTAPI
            mouseData As Long
            flags As Long
            time As Long
            dwExtraInfo As Long
        End Type
        
        Const HC_ACTION = 0
        Const WH_MOUSE_LL = 14
        Const WM_MOUSEWHEEL = &H20A
        
        Dim hhkLowLevelMouse, lngInitialColor As Long
        Dim udtlParamStuct As MSLLHOOKSTRUCT
        Public intTopIndex As Integer
        
        
        Function GetHookStruct(ByVal lParam As Long) As MSLLHOOKSTRUCT
        
           CopyMemory VarPtr(udtlParamStuct), lParam, LenB(udtlParamStuct)
            
           GetHookStruct = udtlParamStuct
            
        End Function
        
        Function LowLevelMouseProc _
        (ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        
            On Error Resume Next
        
            If (nCode = HC_ACTION) Then
                
                If wParam = WM_MOUSEWHEEL Then
                    
                    LowLevelMouseProc = True
                    
                    'ATENÇÃO: Troque o nome do seu Userform
                    With UserForm1
                        
                        'ROLAR PARA CIMA
                        If GetHookStruct(lParam).mouseData > 0 Then
                            .ScrollTop = intTopIndex - 10
                            intTopIndex = .ScrollTop
                        Else
                        'ROLAR PARA BAIXO
                            .ScrollTop = intTopIndex + 10
                            intTopIndex = .ScrollTop
                        End If
                        
                    End With
                    
                End If
                
                Exit Function
                
            End If
        
            UnhookWindowsHookEx hhkLowLevelMouse
            LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
        End Function
        
        Sub Hook_Mouse()
            If hhkLowLevelMouse <> 0 Then
                UnhookWindowsHookEx hhkLowLevelMouse
            End If
                
            hhkLowLevelMouse = SetWindowsHookEx _
            (WH_MOUSE_LL, AddressOf LowLevelMouseProc, Application.Hinstance, 0)
        
        End Sub
        
        Sub UnHook_Mouse()
        
            If hhkLowLevelMouse <> 0 Then UnhookWindowsHookEx hhkLowLevelMouse
            
        End Sub
            
    #End If
Ao exceutar as sugestões citadas acima, apresenta os erros printados.
Screen Shot 10-28-16 at 05.18 PM.JPG
Screen Shot 10-28-16 at 05.31 PM.JPG
Segundo minhas pesquisas realiza a alteração do "Application.Hinstance" para "Application.HinstancePtr", mas ocorre um erro.
Screen Shot 10-28-16 at 05.35 PM.JPG
Excel reinicia, não me deixando analisar o código.
Screen Shot 10-28-16 at 05.35 PM 001.JPG
Obrigado desde já.

humbertops

09-11-2016 17:17:29

Estou com este erro em uma macro, o rapaz que criou não está conseguindo resolver, tenho instalado o Office Profissional 2016 - 64 bits e com windows 10 pro instalado.

Segue o código com erro abaixo:

Option Explicit

Public Declare Function FindWindowA& Lib "user32" (ByVal lpClassName$, ByVal lpWindowName$)
Public Declare Function GetWindowLongA& Lib "user32" (ByVal hWnd&, ByVal nIndex&)
Public Declare Function SetWindowLongA& Lib "user32" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)

' constantes

Public Const GWL_STYLE As Long = -16
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_FULLSIZING = &H70000

Public Sub InitMaxMin(mCaption As String, Optional Max As Boolean = True, Optional Min As Boolean = True _
, Optional Sizing As Boolean = True)
Dim hWnd As Long
hWnd = FindWindowA(vbNullString, mCaption)
If Min Then SetWindowLongA hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) Or WS_MINIMIZEBOX
If Max Then SetWindowLongA hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) Or WS_MAXIMIZEBOX
If Sizing Then SetWindowLongA hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) Or WS_FULLSIZING
End Sub

Mikel Silveira Fraga

10-11-2016 00:44:05

Humbertops, boa noite e seja bem vindo ao fórum.

Cara, veja se o código abaixo resolve seu problema:

Código: Selecionar todos

Public PtrSafe Declare Function FindWindowA& Lib "user32" (ByVal lpClassName$, ByVal lpWindowName$) LongLong
Public PtrSafe Declare Function GetWindowLongA& Lib "user32" (ByVal hWnd&, ByVal nIndex&) LongLong
Public PtrSafe Declare Function SetWindowLongA& Lib "user32" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&) LongLong
Com essa alteração acima, ele irá funcionar somente em versões do Office 64 Bits.

Caso precise que o mesmo arquivo funcione em outras versões do Office, teremos que modificar o código. Segue link abaixo com as orientações:
- VBA Tips - Compatibilidade entre as API 32-Bits (x86) e 64-Bits (x64) no VBA

Dúvidas, estamos a disposição.

Abraços e bom descanso.

AnanaisJr

26-12-2016 14:47:12

Ola Amigos, estou com o mesmo problema em um projeto para abrir pagina da internet pelo o VBA, informando para atualizar o sistema para 64 bits, gostaria de ajuda:

Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Public Function DownloadFilefromWeb(url As String, fileName As String) As Boolean
DownloadFilefromWeb = URLDownloadToFile(0, url, fileName, 0, 0)
End Function

Abraço a todos

Nilmar

21-05-2017 23:27:44

ESTOU COM O MESMO PROBLEMA:

Tentei substituir no meu código para que usuarios de 32bits e de 64 bits possam abrir a minha planilha normalmente, mas o código proposto não executa como deveria nas duas versões. Quero saber se podem me ajudar?

O código proposto:

#If VBA7 Then 'Declaração de API´s para versões do MS Office 2010+.

#If Win64 Then 'Declaração para as versões 64 bits.

Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As LongLong, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As LongLong) As _
LongLong

#Else 'Declaração para as versões 32 bits.

Public Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As LongPtr) As _
LongPtr

#End If

#ElseIf VBA6 Then 'Declaração de API´s para versões do MS Office 2007-.

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As _
Long

#End If

AQUI O MEU CÓDIGO DE 32BITS

Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As Long
Public USUARIO As String
Public Senha As String
Public Nome As String
Public Tipo As String
Public NUsuario As String
Public SenhaNUser As String
Public ConfSenha As String
Public SenhaAdm As String
Public linha As Integer

Por favor, me ajudem a resolver essa dificuldade operacional. Aguardo vosso contato.

Nilmar Spoladori

Mikel Silveira Fraga

24-05-2017 03:09:29

Nilmar, boa noite.

Cara, desculpa de demora em responder, mas esses dias tem sido bem corridos.

Substitua todo o código que você postou aqui pelo código abaixo:

Código: Selecionar todos

Option Explicit

#If VBA7 Then         ' Avalia as versões do Office 2010+
  #If Win64 Then      ' Arquitetura 64 Bits do Office
    Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongLong
    Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongLong
    Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongLong
    Private Declare PtrSafe Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As LongLong
  #ElseIf Win32 Then  ' Arquitetura 32 Bits do Office
    Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare PtrSafe Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As Long
  #End If
#ElseIf VBA6 Then     ' Avalia as versões do Office 2007-
  Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  Private Declare Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As Long
#End If

Public USUARIO As String
Public Senha As String
Public Nome As String
Public Tipo As String
Public NUsuario As String
Public SenhaNUser As String
Public ConfSenha As String
Public SenhaAdm As String
Public linha As Integer
Dessa forma, deve funcionar em todos os sistemas. Teste e nos retorne.

Forte abraço.

Mikel Silveira Fraga

13-06-2017 17:38:19

Nilmar, boa tarde.

Estive fazendo uns testes (2010 e 2013) e consegui adaptar um código que vai atendê-lo melhor.

Código: Selecionar todos

Option Explicit

#If VBA7 Then         ' Avalia as versões do Office 2010+
  Private Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  Private Declare PtrSafe Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  Private Declare PtrSafe Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  Private Declare PtrSafe Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As Long
#ElseIf VBA6 Then     ' Avalia as versões do Office 2007-
  Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  Private Declare Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As Long
#End If

Public USUARIO As String
Public Senha As String
Public Nome As String
Public Tipo As String
Public NUsuario As String
Public SenhaNUser As String
Public ConfSenha As String
Public SenhaAdm As String
Public linha As Integer
Acredito que agora não teremos mais erros.

Teste e nos retorne.

Forte abraço.

alexdias

13-06-2017 20:28:26

Mikel, boa tarde, resolvi o erro do "PtrSafe" mas continuou dando problema conforme imagem em anexo,
se puder me esclarecer serei grato!

Mikel Silveira Fraga

14-06-2017 01:08:00

Alex Dias, boa noite e seja bem vindo ao fórum.

Cara, posso estar enganado, mas o erro entra no mesmo conceito do código anterior, porém para a função LowLeveMouseProc.

Sei que esses conjunto de rotinas serve para ativar o Scroll Button do Mouse nos controles ListBox e ComboBox.
Bem, sobre a rotina, não tenho como te explicar muita coisa, pois estudei pouco esse código e não cheguei a entender 100% do seu funcionamento. Tenho feito alguns trabalhos com esse tipo de código (API´s do Windows), mas este é mais complexo, se comparado com os que já utilizei anteriormente.

Dúvidas, envie o arquivo com esse código completo, pra que possa dar uma melhor orientada.

Fico no aguardo.

Sergiolgluz

26-11-2017 13:26:57

Olá Mikel.
Tenho feito todos os procedimentos para rodar em 64 bit, todavia, quando teclo no botão pesquisar dá o Erro de compilação e diz que é impossível achar a biblioteca. Por favor, me dê auxílio.
Segue trecho do código:

Private Sub UserForm_Initialize()

With lstLista
.ColumnHeaders.Clear
.ListItems.Clear
.Gridlines = True
.View = 3
.FullRowSelect = True
' .ColumnHeaders.Add Text:="ID", Width:=20
' .ColumnHeaders.Add Text:="reclamante", Width:=60
' .ColumnHeaders.Add Text:="processo", Width:=120
' .ColumnHeaders.Add Text:="advogado", Width:=30
' .ColumnHeaders.Add Text:="reclamada", Width:=50
End With

'preenche o cboDirecao e seleciona o primeiro item
cboDirecao.Clear
cboDirecao.AddItem "Ascendente"
cboDirecao.AddItem "Descendente"
cboDirecao.ListIndex = 0

Call DefinePlanilhaDados
Call Populaterceiro
Call PopulaListBox(vbNullString, vbNullString, vbNullString, vbNullString, vbNullString)
End Sub

Sergiolgluz

26-11-2017 13:32:31

Olá Mikel.
Tenho feito todos os procedimentos para rodar em 64 bit, todavia, quando teclo no botão pesquisar dá o Erro de compilação e diz que é impossível achar a biblioteca. Por favor, me dê auxílio.
Segue trecho do código:

Private Sub UserForm_Initialize()

With lstLista
.ColumnHeaders.Clear
.ListItems.Clear
.Gridlines = True
.View = 3
.FullRowSelect = True
' .ColumnHeaders.Add Text:="ID", Width:=20
' .ColumnHeaders.Add Text:="reclamante", Width:=60
' .ColumnHeaders.Add Text:="processo", Width:=120
' .ColumnHeaders.Add Text:="advogado", Width:=30
' .ColumnHeaders.Add Text:="reclamada", Width:=50
End With

'preenche o cboDirecao e seleciona o primeiro item
cboDirecao.Clear
cboDirecao.AddItem "Ascendente"
cboDirecao.AddItem "Descendente"
cboDirecao.ListIndex = 0

Call DefinePlanilhaDados
Call Populaterceiro
Call PopulaListBox(vbNullString, vbNullString, vbNullString, vbNullString, vbNullString)
End Sub

Mikel Silveira Fraga

27-11-2017 11:20:08

Sergio, bom dia.

Cara, pelo que pude ver no seu código, a situação é diferente do post original. Pelo que estou vendo, você esta tentando utilizar o ListView no Office 64, o que era impossível até então. Digo que era, pois fiquei sabendo que no início desse mês, a Microsoft lançou uma atualização, liberando o uso destas bibliotecas nas versões do Office 365 64 bits.

Infelizmente ainda não consegui detalhes sobre esse caso, sei apenas que algumas pessoas estão confirmando que já esta funcionando e esta rodando bem. Grupos de WhatsApp estão mais a par desse assunto do que em fóruns, pelo que fiquei sabendo.

Nessa vou ficar lhe devendo. Espero que tenha sorte em seu problema.

Abraços!!!

Sergiolgluz

27-11-2017 23:34:32

Ok, vou seguir a dica. Agradeço!

Alex Abreu

16-09-2019 12:07:10

Mikel Silveira Fraga escreveu: ↑Ter Jun 13, 2017 10:08 pm Alex Dias, boa noite e seja bem vindo ao fórum.

Cara, posso estar enganado, mas o erro entra no mesmo conceito do código anterior, porém para a função LowLeveMouseProc.

Sei que esses conjunto de rotinas serve para ativar o Scroll Button do Mouse nos controles ListBox e ComboBox.
Bem, sobre a rotina, não tenho como te explicar muita coisa, pois estudei pouco esse código e não cheguei a entender 100% do seu funcionamento. Tenho feito alguns trabalhos com esse tipo de código (API´s do Windows), mas este é mais complexo, se comparado com os que já utilizei anteriormente.

Dúvidas, envie o arquivo com esse código completo, pra que possa dar uma melhor orientada.

Fico no aguardo.
Bom dia Mikel, cá estou eu te pedindo alguma luz no fim do túnel novamente :lol:
Seguinte, me deparei que em casa o Office que eu instalei foi a versão 2016 x64, té então tava usando o Office 2016 x86 (32 Bits)
Só percebi essa troca quando os comandos da API do Mouse Scroll pararam de funcionar, de fato que para muitas declarações eu sempre uso o PtrSafe o que não deu crash em muita coisa porém essa API tem me dado dor de cabeça, cheguei a teu post de 2017 citado acima dando uma pesquisada no google a respeito, por acaso depois de 2 anos tu conseguiu alguma informação nova sobre o uso de Mouse scroll em Combobox e Userform ou Frame em Office x64?

OBS: Acrescentei em anexo os Módulos que eu uso nas versões 32 Bits para ver se ajuda na conversão!
OBS02: Acabei tropeçando neste lugar e acabei achando algo que resolveu paliativamente meu problema (Estou testando no Office 32 Bits do meu trabalho, posteriormente testarei no Office em casa)
01 Módulos e Userforms prontos para uso incluso modulo x64.rar