Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can not run code on 64 byte

Posted on 2014-04-08
5
Medium Priority
?
215 Views
Last Modified: 2014-04-08
The following code will not run on Excel 2013 64 byte,  I would like to be able to run on 32 byte and 64 byte


Private Declare Function GetPrivateProfileStringA Lib _
                                                  "kernel32" (ByVal strSection As Any, _
                                                              ByVal strKey As String, ByVal strDefault As Any, _
                                                              ByVal strReturnedString As Any, _
                                                              ByVal lngSize As Any, ByVal strFileNameName As Any) As Long

Open in new window


Function GetPrivateProfileString32(ByVal strFileName As String, _
                                   ByVal strSection As String, ByVal strKey As String, _
                                   Optional strDefault) As String
    Dim strReturnString As String, lngSize As Long, lngValid As Long
    On Error Resume Next
    If IsMissing(strDefault) Then strDefault = ""
    strReturnString = Space(1024)
    lngSize = Len(strReturnString)
    lngValid = GetPrivateProfileStringA(strSection, strKey, _
                                        strDefault, strReturnString, lngSize, strFileName)
    GetPrivateProfileString32 = Left(strReturnString, lngValid)
    On Error GoTo 0
End Function
0
Comment
Question by:montrof
  • 2
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
MacroShadow earned 2000 total points
ID: 39987229
Try this:
#If Win64 Then
    Private Declare PtrSafe Function GetPrivateProfileStringA Lib _
                                                      "kernel32" (ByVal strSection As Any, _
                                                                  ByVal strKey As String, ByVal strDefault As Any, _
                                                                  ByVal strReturnedString As Any, _
                                                                  ByVal lngSize As Any, ByVal strFileNameName As Any) As Long
#Else
    Private Declare Function GetPrivateProfileStringA Lib _
                                                      "kernel32" (ByVal strSection As Any, _
                                                                  ByVal strKey As String, ByVal strDefault As Any, _
                                                                  ByVal strReturnedString As Any, _
                                                                  ByVal lngSize As Any, ByVal strFileNameName As Any) As Long
#End If

Function GetPrivateProfileString32(ByVal strFileName As String, _
                                   ByVal strSection As String, ByVal strKey As String, _
                                   Optional strDefault) As String
    Dim strReturnString As String, lngSize As Long, lngValid As Long
    On Error Resume Next
    If IsMissing(strDefault) Then strDefault = ""
    strReturnString = Space(1024)
    lngSize = Len(strReturnString)
    lngValid = GetPrivateProfileStringA(strSection, strKey, _
                                        strDefault, strReturnString, lngSize, strFileName)
    GetPrivateProfileString32 = Left(strReturnString, lngValid)
    On Error GoTo 0
End Function

Open in new window

0
 
LVL 1

Author Comment

by:montrof
ID: 39987243
Thank you MacroShadow

When running on 32 byte I get error type mismatch for strDefault.

Montrof
0
 
LVL 28

Expert Comment

by:MacroShadow
ID: 39987256
I don't know. That is a problem with your original code (I only added 64bit support). Please ask new question.
0
 
LVL 12

Expert Comment

by:tel2
ID: 39987356
BTW, Montrof, it's "32 bit" and "64 bit", not "32 byte" and "64 byte".  Only a factor of 8 out, though.
0
 
LVL 1

Author Comment

by:montrof
ID: 39987358
Good point typo
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question