Share via

System PrivateProfileString not working

Anonymous
2011-02-09T15:16:36+00:00

System PrivateProfileString not working

This is specifically a Mac problem. I've got a user template I've been using for years with Office 2003 and 2007. I use the PrivateProfileString method to read/write from a text file. However, when I try to do the same thing in Word 2011 (i.e. the Mac version), I run into problems.

This:

MsgBox System.PrivateProfileString("Macintosh HD:Users:theostar:Documents:txtExpress_2011:initest.txt", "locaties", "xee")

results in an empty message box.

This:

System.PrivateProfileString("Macintosh HD:Users:theostar:Documents:txtExpress_2011:initest.txt", "locaties", "xee") = "wwgd"

returns the following error message:

Run-time error '-2147483640 (80000008) Method ;PrivateProfileString' of object 'System' Failed

I ran a search on the web and found one mention on a forum. Apparently this user had the exact same problem. One of the answers he received was that Microsoft might not have implemented the PrivateProfileString in VBA for Office 2011. The user also mentioned that the same code actually worked in Word 2004.

So, I'm wondering: Am I doing something wrong? Or is it true that this method wasn't implemented in 2011? If not, is there a workaround?

Any answers will be very much appreciated.

Thanks in advance and best regards,

Theo van der Ster

The Netherlands

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Steve Rindsberg 99,166 Reputation points MVP Volunteer Moderator
2012-05-09T15:02:25+00:00

System.PrivateProfileString is almost certainly calling an underlying WinAPI to do the work.

The Windows API will not be available on Mac.

You can use SaveSetting and GetSetting however:

Call SaveSetting("My_App","ThisSection", "ThisKey", "This is the string to save")

Debug.Print GetSetting ("My_App","ThisSection", "ThisKey", "Default string")

This saves settings to Macintosh HD:Users: <username> :Library:Preferences:My_App.plist

The plist file is XML format.

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Steve Rindsberg 99,166 Reputation points MVP Volunteer Moderator
    2012-05-10T19:31:10+00:00

    >> One thing I don't understand is why there's no reference to Microsoft XML on Mac.

    That's not a feature that's built into Office; it's a DLL that some apps may install.

    >> EDIT: I doesn't seem the Call SaveSetting saves the .plist-file in XML format though..

    It does in Office 2011 (I vaguely recall it being in some other format in pre-2008 versions of Mac Office).

    The file will have a .plist extension but open it in a text editor ... it's XML.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-05-10T07:05:44+00:00

    Thanks for answering, Steve!

    Even though System.ProfileString("ThisSection", "ThisKey") = "the string to save" works on Word 2011 for Mac, it seems that your solution is the way to go. I will try it out for sure!

    One thing I don't understand is why there's no reference to Microsoft XML on Mac.

    I'd really like to make a new MSXML.DOMDocument, but I guess that's not possible on Word 2011 for Mac.

    EDIT: I doesn't seem the Call SaveSetting saves the .plist-file in XML format though..

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-05-09T07:20:26+00:00

    I ran in to the same problem and found the following to work:

    System.ProfileString("testing", "test") = "the test"

    MsgBox(System.ProfileString("testing", "test"))

    It works when you don't use PrivateProfileString. But then again it seems like you can't choose what file to store it in.

    The data seems to be stored in the user > library > preference folder and the file com.microsoft.Word.plist

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-02-12T10:04:13+00:00

    We're also experiencing the same issue with Word 2011 and Mac Lion. We would appreciate someone to address this issue. Thanks!

    Was this answer helpful?

    0 comments No comments