troubleshooting Question template in use - VBA

Avatar of jdc1944
jdc1944Flag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft WordVB Script
4 Comments1 Solution849 ViewsLast Modified:
As a bit of a background i have used a word document to add several command buttons.  The document is used as a bit of a menu to open various other documents.  When one of these buttons is pressed the code checks a .ini file for various things before it opens the desired document.

One of the problems i was having with the .ini file is that i wasn't opening/closing the object properly and as a result it didn't take long for a huge amount of WINWORD.EXE proccesses to appear and cause me grief.  To try and prevent this i tried to change the code i had written to open up the .ini file to declare and delete the word.exe objects (if thats what they are called).  This worked and i no longer get the WINWORD.EXE processes still appearing when i had finsihed when them.

This worked for a while but i'm now getting an error message every time i press one of the buttons.

"This file is in use by another application or user. (C:\Documents and Settings\...\"

Now im no expert in VBA but i thought the problem might be that i am creating a word object to look at the .ini file (even though one has already been created automatically to open the Word menu) and i am then trying to delete that object even though it might still be in use by the Word menu.  This menu system is used by about 10 other people who don't get this error message.  I have also tried deleting the template incase that was the isue.

The code i use to open the .ini file is
Function ReadINI(Path As String, Section As String, _
    Key As String) As String
Dim wd As Word.Application
    fileName = Path & "\settings.ini"
    ReadINI = ""
    Set wd = New Word.Application ' create the Word application object
    On Error Resume Next
    ReadINI = wd.System.PrivateProfileString(fileName, Section, Key)
    On Error GoTo 0
    Set wd = Nothing ' destroy the Word application object
End Function

Is there a problem with the way i am reading the .ini file or does it lay with Word and the template?

If it is the code, i still need some way to delete the word object every time i read the .ini file to stop it creating a large amount of redundant processes.

Any Ideas?
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros