Solved

Can not run code on 64 byte

Posted on 2014-04-08
5
205 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 27

Accepted Solution

by:
MacroShadow earned 500 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 27

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
copy same as above data 18 41
Excel change font color in formula 19 31
Excel count if date is greater than Current date 1 22
VBA working with shapes 6 11
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

830 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