PDA

View Full Version : [SOLVED:] Close instance of Excel from word



ScotWW
09-23-2017, 10:30 PM
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

macropod
09-23-2017, 11:01 PM
Simply insert:
myexcel.Quit
after:
myWB.Close False

ScotWW
09-24-2017, 12:05 AM
That worked wonderfully. Thank you Paul. Which brings me to a new question. I will post a new thread..