Clever-Excel-Forum

Normale Version: PtrSafe
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo Leute, 

ich habe folgendes Problem:

Ich habe eine Excelvorlage mit Makros erstellt, verschicke ich diese bekomme ich folgenden Fehler:

Datei ist beschädigt und kann nicht geöffnet werden.

an meinem PC mit Office 2007 kann ich diese immerhin öffnen, allerdings mit einem Fehler im VBA:

Code:
Option Explicit

Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hwnd As LongPtr, _
        ByVal hWndInsertAfter As LongPtr, ByVal x As Long, ByVal y As Long, _
        ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare PtrSafe Function SetDlgItemText Lib "user32" Alias "SetDlgItemTextA" ( _
        ByVal hDlg As LongPtr, ByVal nIDDlgItem As Long, ByVal lpString As String) As Long
Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function MessageBox Lib "user32" Alias "MessageBoxA" ( _
        ByVal hwnd As LongPtr, ByVal lpText As String, ByVal lpCaption As String, _
        ByVal wType As Long) As Long
Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" ( _
        ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, _
        ByVal dwThreadId As Long) As LongPtr
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" ( _
        ByVal hhk As LongPtr) As Long

#If Win64 Then
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongPtrA" ( _
        ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongA" ( _
        ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
#End If
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare PtrSafe Function GetWindowRect Lib "user32" ( _
        ByVal hwnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" ( _
        ByVal nIndex As Long) As Long

Da wird das erste PtrSafe markiert und der Fehler Fehler beim Kompilieren: Erwartet: Sub oder Function ausgegeben.
Dann ist soweit auch alles rot.

Der PC an dem die Datei erstellt wurde hat dieselbe 64-bit Version, wie der PC zu dem ich die Datei ursprünglich per Mail versendet habe.


Kann mir jemand helfen?
Hallo,

Office 2007 kennt noch kein PtrSafe, das geht erst ab Office 2010. Du musst somit zusätzlich VBA7 als Kompilerkonstante
verwenden, wenn Du die Anwendung in Office 2007 verwenden möchtest.

https://docs.microsoft.com/de-de/office/...fe-keyword

docs.microsoft.com/de-de/office/client-developer/shared/compatibility-between-the-32-bit-and-64-bit-versions-of-office

Hinweis: der zweite Link lässt sich nicht einfügen.

Gruß