Hello,
I've created an add in from which I am trying to build user settings but am getting stuck returning the stored values in the INI file.
Please help.
Code I have has is:-
![]()
Please Login or Register to view this content.
Hello,
I've created an add in from which I am trying to build user settings but am getting stuck returning the stored values in the INI file.
Please help.
Code I have has is:-
![]()
Please Login or Register to view this content.
Last edited by SystemsAccountant; 04-19-2010 at 04:07 AM. Reason: Solved
Hello System Accountant,
The first rule of using API calls: Do not take short cuts when coding!
It appears you have the API calls in the General Declarations section of the UserForm. The calls won't be available until the UserForm is loaded. These calls need to moved into a separate VBA module.
Copy this code into its own VBA module. This contains 2 new macro that will be called by the UserForm. I added these for safety. The API does little error checking and if you are not familiar will all the options a call has, things can get screwed up fast.
![]()
Please Login or Register to view this content.
UserForm Code
Here are the API calls with comments about how they function...![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Excellent Leith, thank you
I have no real idea about most of the code and I've just been searching the web and playing with the code for many hours trying to get it to work.
I've put the code in but get a compile error on:-
Within the Writeprivatedata![]()
Please Login or Register to view this content.
Is this because the INI file does not exist yet? I of course would like it to write one if one does not exist yet with a default value of true.
Kind Regards
Matt
Hello Matt,
The API will create the file if it doesn't exist. The problem is I didn't change my API code to match yours. I have made the correction in this version. The code will works correctly with Windows 2000 through Xp. If you are using 2007 or later, I am not sure it work correcly. Microsoft has made no notations to the API page about this. If you still have problems, post your workbook so I can review it.
![]()
Please Login or Register to view this content.
Thanks Leith, still have the same problem I'm afraid.
Code used within the Userform:-
Code used on a separate module![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
I'm not really sure about any of this but as far as I can see I can't see anything that stipulates the INI file itself and it's directory (current directory of active workbook)?
I tried attaching the file - it's an excel add in so resaved as abn xls file.
Kind Regards
Matt
Hello Matt,
Okay, I found the problem. My mistake. I forgot that I created WritePrivateData as a SUb and not a Function. The error occurs because I was trying to assign it a return value. Copy this code over the WritePrivateData code of the macro in the UserProfileSettings.
Correct Code
![]()
Please Login or Register to view this content.
Cheers Leith,
Working now with the exception that when the userform is called it does not return the stored INI setting.
It looks like when I run the userform and click the checkbox it's not passing this through to INI file.
Separate question:
Do I need to use CInt to pass the results of the checkbox to the INI file? Would it work just as well with True / False. I tried this and it doesn't help with the above problem.
Regards
Matt
FWIW, you could also just write to the registry using SaveSetting and GetSetting with no APIs needed.![]()
Everyone who confuses correlation and causation ends up dead.
Hello,
I still have not been able to figure out how to pull the value from the INI file into the userform checkbox.
I've not got this working.
Created a message box in a module instead which works easy enough. Couldn't work out how to get the userform working.
Refer to attched workbook example with User Form prererence get, save & reset
Or store the users' setting on a hidden sheet, with control names down the left column, usernames across the top, and control values in the body of the table.FWIW, you could also just write to the registry using SaveSetting and GetSetting with no APIs needed.
Entia non sunt multiplicanda sine necessitate
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks