Clever-Excel-Forum

Normale Version: Unterschied Excel 32 bit - 64 bit
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Seiten: 1 2
Hallo zusammen,

ich habe eine recht umfangreiche Datei, welche bei mir, Excel 365 32 bit, läuft aber nicht bei anderen welche 64 bit nutzen. Wo liegt der Unterschied zwischen den Versionen? Wie kann ich jetzt diese Fehler ausmerzen? Hat einer von euch VBA programmierenden, eine 64 bit Version?

Gruß
Marcus
Hallo LCohen,

entschuldige, wenn ich nicht so schlau bin, wie ihr es seit. Heißt das, dass ich alle Public in Declare umwandeln muss?

Code:
Public/Private Declare Sub

Der Text von Microsoft ist wiedersprüchlich. Alle 32 bit Versionen sollen auf 64 bit laufen. Aber ...

Stehe genauso schlau da wie vorher.

Aber Danke für deine Antwort.

Gruß
Marcus
Hallo Marcus,

(01.03.2020, 15:15)marose67 schrieb: [ -> ]entschuldige, wenn ich nicht so schlau bin, wie ihr es seit.

Dafür gibt es ja die Suche (auch hier im Forum)! Wink

https://www.clever-excel-forum.de/search...on=results&sid=b761d0ccfa2f589f52f5c29d9a40cd9c&sortby=lastpost&order=desc

Gruß Uwe
Hallo,

kann es sein, dass das Problem hier liegt?

' Der Code für das Entfernen des Schließkreuzes wurde von Nepumuk im Herber Forum veröffentlicht
Private Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000

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


Dieser COde bezieht sich darauf:

Private Sub UserForm_activate()
    Dim xl_hwnd, lStyle
    xl_hwnd = FindWindow(vbNullString, Me.Caption)
    If xl_hwnd <> 0 Then
        lStyle = GetWindowLong(xl_hwnd, GWL_STYLE)
        lStyle = SetWindowLong(xl_hwnd, GWL_STYLE, lStyle And Not WS_SYSMENU)
        DrawMenuBar xl_hwnd
    End If
End Sub

Edit:

Könnte das die Lösung sein?

Option Explicit

' Der Code für das Entfernen des Schließkreuzes wurde von Nepumuk im Herber Forum veröffentlicht
Private Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000
#If Win64 Then
  Public Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" _
      (ByVal lpClassName As String, ByVal lpWindowName As String) As ptrLong
  Public Declare PtrSafe Function SetWindowPos Lib "User32" (ByVal hwnd As Long, _
      ByVal hWndInsertAfter As ptrLong, ByVal X As ptrLong, ByVal Y As ptrLong, _
          ByVal cx As ptrLong, ByVal cy As ptrLong, ByVal wFlags As ptrLong) As ptrLong
  Declare PtrSafe Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As ptrLong) As ptrLong
#Else
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


Liebe Grüße
Marcus
Hallo,

die (meisten und gebräuchlichsten) Windows API Deklarationen für VBA findest Du hier in diesem Download-Link ...

https://www.microsoft.com/en-us/download...px?id=9970

Entpackt, landet das Ganze dann in C:\Office 2010 Developer Resources\Documents\Office2010Win32API_PtrSafe.

Je nach Excel-Bit-Version sind die Windows API's in ihrer Deklaration unterschiedlich bzw. rufen auch manchmal
unterschiedliche API's auf, wie z.B. bei GetWindowLongA. Die Bit-Version steuerst Du mit der in VBA integrierten
Compiler-Konstante #Win64. 

Dein Code würde wie folgt aussehen, jetzt ungetestet in Excel 64 Bit. Der Code setzt mindestens Excel 2010 voraus.
Und ich würde auch empfehlen, bei der Verwendung von Windows-API Variablen korrekt zu typisieren.

Code:
Private Const GWL_STYLE = (-16)
  Private Const WS_SYSMENU = &H80000

  Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hwnd As LongPtr) As Long
 
  Private Declare PtrSafe Function FindWindow Lib "user32" _
          Alias "FindWindowA" (ByVal lpClassName As String, _
          ByVal lpWindowName As String) As LongPtr

#If Win64 Then
 
  Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" _
          Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, _
          ByVal nIndex As Long) As LongPtr
         
  Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" _
          Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, _
          ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
 
#Else

  Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" _
          Alias "GetWindowLongA" (ByVal hwnd As LongPtr, _
          ByVal nIndex As Long) As LongPtr
         
  Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" _
          Alias "SetWindowLongA" (ByVal hwnd As LongPtr, _
          ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr

#End If
 
  Private Sub UserForm_Activate()
   
    Dim xl_hwnd As LongPtr
    Dim lStyle  As Long
   
    xl_hwnd = FindWindow(vbNullString, Me.Caption)
   
    If xl_hwnd <> 0 Then
   
        lStyle = GetWindowLongPtr(xl_hwnd, GWL_STYLE)
        lStyle = SetWindowLongPtr(xl_hwnd, GWL_STYLE, lStyle And Not WS_SYSMENU)
        DrawMenuBar xl_hwnd
       
    End If

Gruß
Hallo,

ich habe die Datei mal verschickt. Bin auf die Antwort gespannt. Auf 32 Bit läuft die auf alle Fälle. Danke für Deine Hilfe!

Gruß
Marcus
Hallo,
ich habe eine Antwort bekommen. Dort kommt wohl noch immer ein Fehler. Folgende Microsoft Meldung wurde mir übermittelt:
https://docs.microsoft.com/de-de/office/vba/language/reference/user-interface-help/you-must-terminate-the-if-block-with-an-end-if?redirectedfrom=MSDN

#End If
lag in dem Code aber doch vor! Hat noch jemand einen Tipp?

Gruß
Marcus
Hi Markus,

Dein Link läuft bei mir auf einen Seitenfehler Sad

Trotzdem ein Hinweis. Da steht im code

...
Dim lStyle  As Long

lStyle = GetWindowLongPtr(xl_hwnd, GWL_STYLE)

Da wäre

Dim lStyle  As LongPtr

die bessere Wahl Huh
Hallo Markus,

sorry - ich hatte mich beim Reinkopieren des Codes hier ins Forum leider vertan: es muss Dim lStyle As LongPtr heißen, denn LongPtr
wird als Rückgabedatentyp von GetWindowLongPtr erwartet. Ich hab's jetzt auch mal in Excel 64 Bit getestet. Code in der Datei im Anhang.
Müsste nun gehen.

Gruß
Seiten: 1 2