Excel vba GetPrivateProfileString可以在2007年工作,但不能在2010年 [英] Excel vba GetPrivateProfileString working 2007, but not 2010

查看:263
本文介绍了Excel vba GetPrivateProfileString可以在2007年工作,但不能在2010年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我声明了以下代码:

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

我有如下功能来访问它:

And i have a function to access it as follows:

Private Function ReadIniFileString(ByVal Sect As String, ByVal Keyname As String) As   String
Dim Worked As Long
Dim RetStr As String * 128
Dim StrSize As Long
Dim iNoOfCharInIni As Long
Dim sIniString As String
Dim sProfileString As String

iNoOfCharInIni = 0
sIniString = ""
If Sect = "" Or Keyname = "" Then
   MsgBox "Section Or Key To Read Not Specified !!!", vbExclamation, "INI"
Else
   sProfileString = ""
RetStr = Space(128)
StrSize = Len(RetStr)
Worked = GetPrivateProfileString(Sect, Keyname, "", RetStr, StrSize, IniFileName)
   If Worked Then
      iNoOfCharInIni = Worked
      sIniString = Left$(RetStr, Worked)
   End If
 End If
ReadIniFileString = sIniString
End Function

这在2007年有效,但是我在Excel 2010上遇到了以下错误:

This works under 2007, but i get an error on Excel 2010 at the:

Worked = GetPrivateProfileString(Sect, Keyname, "", RetStr, StrSize, IniFileName)

我在网络上看到我找不到子或函数错误",我应该能够通过在PtrSafe声明函数并返回LongPtr来解决此问题.我已经做到了,但是得到了相同的结果!

i get an "Can't find sub or function error" I have seen on the web that i should be able to fix this via declaring the function at PtrSafe, and returning a LongPtr. I've done that but get the same results!

请帮忙!

非常感谢!

俄罗斯

推荐答案

要在64位版本的Excell中实现此功能,您需要将PtrSafe属性添加到函数声明中,如下所示:

To make this work in a 64 bit version of Excell you need to add the PtrSafe Attribute to the function Declaration like so:

Declare PtrSafe Function GetPrivateProfileString Lib "kernel32" Alias...

这篇关于Excel vba GetPrivateProfileString可以在2007年工作,但不能在2010年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆