Share via

Run-time error when using PrivateProfileString function

Anonymous
2010-10-15T18:38:25+00:00

Hi,

I've created a raffle ticket numbering system where I've set 2 bookmarks on each side of a raffle ticket so that the numbers can be matched later in a draw.

I use PrivateProfileString twice in the macro once to read the incoming value

   SerialNumber = System.PrivateProfileString("C:\Settings.Txt", "MacroSettings", "SerialNumber") 

which works fine (ie it gets the number) and the 2nd time to write the last number back to the file (so if I need extra the last count is already there).   Everything works fine except that when it gets to writing the last number to the file (Settings.txt   just like in the example)

   System.PrivateProfileString("C:\Settings.txt", "MacroSettings", "SerialNumber") = SerialNumber1

It give the error box "Run-time error '-2147467259 (80004005)': Method 'PrivateProfileString' of object 'System' failed".  And yes, SerialNumber1 is a real number - I walked thru the debug step by step.  I thought it might be some permission thing with Win 7 (running word 2010) but I gave full access and still the same thing.  Help!

Thanks, Kevin

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

2 answers

Sort by: Most helpful
  1. Anonymous
    2010-10-16T05:25:23+00:00

    Thanks, will check that out.

    Kevin

    Was this answer helpful?

    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2010-10-15T22:56:19+00:00

    Try using the GetSetting and SaveSetting methods.  Check out the help in the Visual Basic Editor for the syntax.

    -- Hope this helps.

    Doug Robbins - Word MVP,

    dkr[atsymbol]mvps[dot]org

    Posted via the Community Bridge

    "kam5FCC" wrote in message news:*** Email address is removed for privacy ***...

    Hi,

    I've created a raffle ticket numbering system where I've set 2 bookmarks on each side of a raffle ticket so that the numbers can be matched later in a draw.

    I use PrivateProfileString twice in the macro once to read the incoming value

       SerialNumber = System.PrivateProfileString("C:\Settings.Txt", "MacroSettings", "SerialNumber")

    which works fine (ie it gets the number) and the 2nd time to write the last number back to the file (so if I need extra the last count is already there).   Everything works fine except that when it gets to writing the last number to the file (Settings.txt   just like in the example)

       System.PrivateProfileString("C:\Settings.txt", "MacroSettings", "SerialNumber") = SerialNumber1

    It give the error box "Run-time error '-2147467259 (80004005)': Method 'PrivateProfileString' of object 'System' failed".  And yes, SerialNumber1 is a real number - I walked thru the debug step by step.  I thought it might be some permission thing with Win 7 (running word 2010) but I gave full access and still the same thing.  Help!

    Thanks, Kevin


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org

    Was this answer helpful?

    0 comments No comments