+ Reply to Thread
Results 1 to 4 of 4

Cannot destroy Word Object in Excel

  1. #1
    Registered User
    Join Date
    03-23-2006
    Location
    UK
    Posts
    7

    Thumbs up Cannot destroy Word Object in Excel

    I'm using a Word object to write information to the registry from within an Excel Macro (this is in order to generate a PDF file using CutePDF). Everything works fine but the Winword object is still resident in memory.

    The code is as follows:

    Function SetRegKeys(Section as String, Key as String, KeyValue) as Boolean
    Dim wrd As Word.Application
    SetRegistrySetting = False
    Set wrd = New Word.Application
    On Error Resume Next
    wrd.System.PrivateProfileString("", Section, Key) = CStr(KeyValue)
    On Error GoTo 0
    Set wrd = Nothing
    SetRegistrySetting = True
    End Function

    It's probably self evident but I should add that I am no VBA expert.

    Thanks

  2. #2
    Jim Thomlinson
    Guest

    RE: Cannot destroy Word Object in Excel

    You need to close the application before you set it to nothing...

    wrd.close
    set wrd = nothing

    --
    HTH...

    Jim Thomlinson


    "dai50" wrote:

    >
    > I'm using a Word object to write information to the registry from within
    > an Excel Macro (this is in order to generate a PDF file using CutePDF).
    > Everything works fine but the Winword object is still resident in
    > memory.
    >
    > The code is as follows:
    >
    > Function SetRegKeys(Section as String, Key as String, KeyValue) as
    > Boolean
    > Dim wrd As Word.Application
    > SetRegistrySetting = False
    > Set wrd = New Word.Application
    > On Error Resume Next
    > wrd.System.PrivateProfileString("", Section, Key) = CStr(KeyValue)
    > On Error GoTo 0
    > Set wrd = Nothing
    > SetRegistrySetting = True
    > End Function
    >
    > It's probably self evident but I should add that I am no VBA expert.
    >
    > Thanks
    >
    >
    > --
    > dai50
    > ------------------------------------------------------------------------
    > dai50's Profile: http://www.excelforum.com/member.php...o&userid=32741
    > View this thread: http://www.excelforum.com/showthread...hreadid=556470
    >
    >


  3. #3
    NickHK
    Guest

    Re: Cannot destroy Word Object in Excel

    I'm curious as why you are using Word to write to the Registry, if this code
    is in Excel.
    If VBA Savesetting cannot save to the correct key, the API versions
    certainly can.

    NickHK

    "dai50" <[email protected]> wrote in message
    news:[email protected]...
    >
    > I'm using a Word object to write information to the registry from within
    > an Excel Macro (this is in order to generate a PDF file using CutePDF).
    > Everything works fine but the Winword object is still resident in
    > memory.
    >
    > The code is as follows:
    >
    > Function SetRegKeys(Section as String, Key as String, KeyValue) as
    > Boolean
    > Dim wrd As Word.Application
    > SetRegistrySetting = False
    > Set wrd = New Word.Application
    > On Error Resume Next
    > wrd.System.PrivateProfileString("", Section, Key) = CStr(KeyValue)
    > On Error GoTo 0
    > Set wrd = Nothing
    > SetRegistrySetting = True
    > End Function
    >
    > It's probably self evident but I should add that I am no VBA expert.
    >
    > Thanks
    >
    >
    > --
    > dai50
    > ------------------------------------------------------------------------
    > dai50's Profile:

    http://www.excelforum.com/member.php...o&userid=32741
    > View this thread: http://www.excelforum.com/showthread...hreadid=556470
    >




  4. #4
    Registered User
    Join Date
    03-23-2006
    Location
    UK
    Posts
    7

    Re: Cannot destroy Word Object in Excel

    Re: Cannot destroy Word Object in Excel
    Nick
    This is the only method I found (on a forum) to write to the Registry. I was also perplexed as to why a word object was used and would prefer a less convoluted process. I found that using
    Wrd.Application.Quit

    prior to

    set wrd = nothing

    removed word from memory and resolved the problem but I'll check your suggestion - so may be here soon.

    Many Thanks

    Dai


    ____________________________________
    I'm curious as why you are using Word to write to the Registry, if this code
    is in Excel.
    If VBA Savesetting cannot save to the correct key, the API versions
    certainly can.

    NickHK

    "dai50" <[email protected]> wrote in message
    news:[email protected]...
    >
    > I'm using a Word object to write information to the registry from within
    > an Excel Macro (this is in order to generate a PDF file using CutePDF).
    > Everything works fine but the Winword object is still resident in
    > memory.
    >
    > The code is as follows:
    >
    > Function SetRegKeys(Section as String, Key as String, KeyValue) as
    > Boolean
    > Dim wrd As Word.Application
    > SetRegistrySetting = False
    > Set wrd = New Word.Application
    > On Error Resume Next
    > wrd.System.PrivateProfileString("", Section, Key) = CStr(KeyValue)
    > On Error GoTo 0
    > Set wrd = Nothing
    > SetRegistrySetting = True
    > End Function
    >
    > It's probably self evident but I should add that I am no VBA expert.
    >
    > Thanks
    >
    >
    > --
    > dai50

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1