Consulting

Results 1 to 3 of 3

Thread: Close instance of Excel from word

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    12
    Location

    Close instance of Excel from word

    Hi,

    I'm writing to and reading from excel with a thrown together file with the structure below.

    Each time I call a function with the same structure, a new instance of excel is created. I would like to neatly close off the new instances of excel when i close the workbook i've been working in.

    Is there a one line modification I can make to the bottom of the code to not only close the workbook but the additional instance of excel opened? Thank you

    'save project data to the configFile for later use
    Private Sub saveProjectTextBoxes()
    Dim myexcel As Object
    Dim myWB As Object
    Set myexcel = CreateObject("Excel.Application")
    Set myWB = myexcel.Workbooks.Open(ActiveDocument.Path & "/ConfigFile.xlsm")
    myexcel.Visible = True


    myWB.sheets("Singular TextBoxes").Cells(7, 6) = "Row7,Col6"
    txtReplyDays.Text = myWB.sheets("Singular TextBoxes").Cells(3, 4)


    myWB.Save
    myWB.Close False
    Set myexcel = Nothing
    Set myWB = Nothing


    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Simply insert:
    myexcel.Quit
    after:
    myWB.Close False
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    May 2017
    Posts
    12
    Location
    That worked wonderfully. Thank you Paul. Which brings me to a new question. I will post a new thread..

Tags for this Thread

Posting Permissions

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