2013 ..muss f��r die Verwendung auf 64-Bit-System . / SolidWorks
Branscheid-GmbH 21. Dez. 2012, 15:08

Hallo,

ein "altes" Makro läuft seit SW2013 nicht mehr, da :

"der Code in diesem Projekt muss für die Verwendung auf 64-Bit-Systemen aktualisiert werden. Überarbeiten und aktualisieren Sie Declare-Anweisungen, und markieren Sie sie mit dem PtrSafe-Attribut".

Kann mir jemand bitte sagen was ich da eintragen muss ?!

Folgende Zeilen sind "rot" markiert, weil ...
==========================================================
Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

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

Es wäre sehr nett, wenn mir jemand dabei helfen könnte !!

Ansonsten wünsche ich frohe Festtage !

HenryV 21. Dez. 2012, 15:36

Hallo

Eigendlich sollte es reichen wenn du nach "Declare" "PtrSafe" reinschreibst.
Näheres dazu findes du hier https://forum.solidworks.com/docs/DOC-2141

Andererseits sollte der Code um ein MakroFenster in den Vordergrund zu bringen in SWX2013 64bit nicht mehr nötig sein, da die mit VBA7 laufen.

Gruss Andreas

Branscheid-GmbH 21. Dez. 2012, 15:48

Ich habe es versucht, aber muss in der Schreibweise etwas falsch gemacht haben.

Wie sollte es Deiner Meinung nach eingetragen werden ?

HenryV 21. Dez. 2012, 16:13

Vieleicht so...

Code:
#If VBA7 Then
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
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#Else
Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If

Branscheid-GmbH 21. Dez. 2012, 16:54

TOP !!!!

Vielen herzlichen Dank - auch im Namen meiner Kollegen,
die jetzt wieder schneller die Schriftfelder ausfüllen können.

Bin froh, dass es solch eine Anlaufstelle mit vielen kompetenten + hilfsbereiten Menschen gibt !!

Nase81 13. Nov. 2017, 10:22

Hallo,

ich habe ein ähnliches Problem. Ich habe vor Jahren mal ein Makro zum speichern unserer unserer e-mails geschrieben/zusammenkopiert.
Haben jetzt auf das 64bit Office umgestellt und ich bekomme das ding nicht mehr zum laufen. Habe das makro analog oben angepasst, bin mir aber nicht sicher welche Variablen-Deklarationen ich von Long auf LongPtr umstellen muss?:

Kann mir da jemand weiterhelfen?

Code:

Private Const EXM_OPT_FILENAME_BUILD As String = "em_<DATE>_<SUBJECT>"
Private Const EXM_OPT_CLEANSUBJECT_REGEX As String = "RE:\s|Re:\s|AW:\s|FW:\s|WG:\s|SV:\s|Antwort:\s"
Private Const EXM_OPT_FILENAME_DATEFORMAT As String = "mmdd"
Private Const MAX_PATH = 260

Private Type OpenFilename
lStructSize As Long
hWndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_CREATEPROMPT = &H2000
Private Const OFN_ENABLEHOOK = &H20
Private Const OFN_ENABLETEMPLATE = &H40
Private Const OFN_ENABLETEMPLATEHANDLE = &H80
Private Const OFN_EXPLORER = &H80000
Private Const OFN_EXTENSIONDIFFERENT = &H400&
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_HIDEREADONLY = &H4&
Private Const OFN_LONGNAMES = &H200000
Private Const OFN_NOCHANGEDIR = &H8&
Private Const OFN_NODEREFERENCELINKS = &H100000
Private Const OFN_NOLONGNAMES = &H40000
Private Const OFN_NONETWORKBUTTON = &H20000
Private Const OFN_NOTESTFILECREATE = &H10000
Private Const OFN_OVERWRITEPROMPT = &H2&
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_READONLY = &H1
Private Const OFN_SHAREAWARE = &H4000
Private Const OFN_SHAREFALLTHROUGH = 2
Private Const OFN_SHAREWARN = 0
Private Const OFN_SHARENOWARN = 1
Private Const OFN_SHOWHELP = &H10
Private Const OFS_MAXPATHNAME = 128

#If VBA7 Then
Private Declare PtrSafe Function GetSaveFileName Lib "comdlg32" _
Alias "GetSaveFileNameA" ( _
lpOpenfilename As OpenFilename) As Long

Private Declare PtrSafe Function CommDlgExtendedError Lib "comdlg32" () As Integer

Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As Long

#Else
Private Declare Function GetSaveFileName Lib "comdlg32" _
Alias "GetSaveFileNameA" ( _
lpOpenfilename As OpenFilename) As Long

Private Declare Function CommDlgExtendedError Lib "comdlg32" () As Integer

Private Declare Function GetActiveWindow Lib "user32" () As Long
#End If

Public Sub Speichern_unter_EIN(MainPath As String)

Dim myExplorer As Outlook.Explorer
Dim myfolder As Outlook.MAPIFolder

Set myExplorer = Application.ActiveExplorer
Set myfolder = myExplorer.CurrentFolder

End Sub

Public Sub Speichern_unter(MainPath As String)

Dim myExplorer As Outlook.Explorer
Dim myfolder As Outlook.MAPIFolder
Dim myItem As Object
Dim olSelection As Selection

Dim myMailItem As MailItem
Dim strDate As String
Dim strSender As String
Dim strReceiver As String
Dim strSubject As String
Dim strFinalFileName As String
Dim strFullPath As String

Set myExplorer = Application.ActiveExplorer
Set myfolder = myExplorer.CurrentFolder
If myfolder Is Nothing Then Error 5001
If Not myfolder.DefaultItemType = olMailItem Then GoTo ExitScript

If myExplorer.Selection.Count > 1 Then
MsgBox "Bitte nur eine E-Mail auswehlen"
GoTo ExitScript
End If

If myExplorer.Selection.Count = 0 Then
MsgBox "Bitte eine E-Mail auswehlen"
GoTo ExitScript
End If

Set olSelection = myExplorer.Selection
For Each myItem In olSelection
If TypeOf myItem Is MailItem Then Set myMailItem = myItem

strDate = Format(myMailItem.ReceivedTime, EXM_OPT_FILENAME_DATEFORMAT)
strSender = myMailItem.SenderName
strReceiver = myMailItem.To
If InStr(strReceiver, ";") > 0 Then strReceiver = Left(strReceiver, InStr(strReceiver, ";") - 1)
strSubject = myMailItem.Subject
strFinalFileName = EXM_OPT_FILENAME_BUILD
strFinalFileName = Replace(strFinalFileName, "<DATE>", strDate)
strFinalFileName = Replace(strFinalFileName, "<SENDER>", strSender)
strFinalFileName = Replace(strFinalFileName, "<RECEIVER>", strReceiver)
strFinalFileName = Replace(strFinalFileName, "<SUBJECT>", strSubject)
strFinalFileName = CleanString(strFinalFileName)
If Left(strFinalFileName, 15) = "ERROR_OCCURRED:" Then
strErrorMsg = Mid(strFinalFileName, 16, 9999)
Error 1003
End If
strFinalFileName = IIf(Len(strFinalFileName) > 251, Left(strFinalFileName, 251), strFinalFileName)

Flt$ = "Outlook Nachrichtenformat (.msg)|*.msg|"
FName$ = GetSaveName(Flt$, "msg", MainPath, strFinalFileName)

If FName$ = "" Then
GoTo ExitScript
Else
myMailItem.SaveAs FName$, olMSG
End If
 
myMailItem.Categories = "gespeichert"
myMailItem.Save
 
Next

ExitScript:

End Sub

Private Function CleanString(strData As String) As String

Const PROCNAME As String = "CleanString"

On Error GoTo ErrorHandler

Dim objRegExp As Object
Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.Global = True

objRegExp.Pattern = EXM_OPT_CLEANSUBJECT_REGEX
strData = objRegExp.Replace(strData, "")

strData = Replace(strData, Chr(9), "_")
strData = Replace(strData, Chr(10), "_")
strData = Replace(strData, Chr(13), "_")
objRegExp.Pattern = "[/\\*]"
strData = objRegExp.Replace(strData, "-")
objRegExp.Pattern = "[""]"
strData = objRegExp.Replace(strData, "'")
objRegExp.Pattern = "[:?<>\|]"
strData = objRegExp.Replace(strData, "")

objRegExp.Pattern = "\s+"
strData = objRegExp.Replace(strData, " ")
objRegExp.Pattern = "_+"
strData = objRegExp.Replace(strData, "_")
objRegExp.Pattern = "-+"
strData = objRegExp.Replace(strData, "-")
objRegExp.Pattern = "'+"
strData = objRegExp.Replace(strData, "'")

strData = Trim(strData)

CleanString = strData


ExitScript:
Exit Function
ErrorHandler:
CleanString = "ERROR_OCCURRED:" & "Error #" & Err & ": " & Error$ & " (Procedure: " & PROCNAME & ")"
Resume ExitScript
End Function

Private Function PrepareFilter(Flt$) As String
Const O$ = "|"
Dim Temp$
Dim i As Integer
Temp$ = Flt$
i = 1
Do While InStr(i, Flt$, O$) <> 0
PrepareFilter = PrepareFilter + _
Mid(Temp$, i, InStr(i, Temp$, O$) - i) + vbNullChar
i = InStr(i, Temp$, O$) + Len(O$)
Loop
PrepareFilter = PrepareFilter + _
Right(Temp$, Len(Temp$) - i + 1) + vbNullChar
End Function

Public Function GetSaveName(ByVal Filter$, ByVal DefExt$, ByVal InitialDir$, ByVal InitialName$) As String

Dim OFN As OpenFilename
Dim Temp$
Dim n As Integer

With OFN
.lStructSize = Len(OFN)
.hWndOwner = GetActiveWindow()
.lpstrFilter = PrepareFilter(Filter$)
.lpstrFile = InitialName$ & String$(700, vbNullChar)
.nMaxFile = 700
.lpstrFileTitle = String$(MAX_PATH, vbNullChar)
.nMaxFileTitle = MAX_PATH
.lpstrInitialDir = InitialDir$
.lpstrTitle = "Speichern unter"
.Flags = OFN_EXTENSIONDIFFERENT Or _
OFN_NOCHANGEDIR Or OFN_OVERWRITEPROMPT _
Or OFN_HIDEREADONLY
.lpstrDefExt = DefExt$
End With

If GetSaveFileName(OFN) Then
Temp$ = OFN.lpstrFile
n = InStr(Temp$, vbNullChar)
If n > 1 Then
GetSaveName = Left$(Temp$, n - 1)
Else
GetSaveName = ""
End If
Else
GetSaveName = ""
End If


End Function




[Diese Nachricht wurde von Nase81 am 13. Nov. 2017 editiert.]

StefanBerlitz 14. Nov. 2017, 08:44

Hallo Nase81,

und herzlich willkommen im SolidWorks-Brett auf Cad.de 

Schau mal auf http://www.jkp-ads.com/articles/apideclarations.asp , da findest du eine gute Übersicht mit den Beschreibungen bei welchen der API-Funktion welche Parameter wie deklariert werden müssen. Statt GetSaveFileName schaust du entsprechend bei GetOpenFileName mit dem Beispiel.

Ciao,
Stefan

PS: deine Frage wäre vielleicht besser im Office oder noch besser VBA-Brett aufgehoben, falls der Tipp dir nicht schon hilft.