0

What's wrong on the function below. Excel.exe*32 not closing in task manager.

Function formatExcel()
    Dim FileName As String
    FileName = "C:\This file\queryCentering.xlsx"
    Set xl = New Excel.Application
    Set wb = xl.Workbooks.Open(FileName)
    With wb.Sheets(1)
        Columns("E:E").Select
        Selection.NumberFormat = "m/d/yyyy"        

        Columns("C:C").HorizontalAlignment = xlCenter
        Rows("2:2").Select 
        Range(Selection, Selection.End(xlDown)).Select  
        Selection.RowHeight = 15 

    End With
    wb.Save
    wb.Close True
    Set wb = Nothing
    xl.Quit
    Set xl = Nothing
End Function
1
  • What are you doing with Selection.RowHeight = 15? Seems like the end result is to select some cells but what happens with that? Commented Sep 8, 2016 at 17:00

2 Answers 2

1

You have With wb.Sheets(1), but don't actually use it.

Also, it is advisable to not use the Selection object.

Try this (note the . before Columns)

With wb.Sheets(1)
    .Columns("E:E").NumberFormat = "m/d/yyyy"        
    .Columns("C:C").HorizontalAlignment = xlCenter
End With
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks- how do I translate this below into .row Rows("2:2").Select Range(Selection, Selection.End(xlDown)).Select Selection.RowHeight = 15
@pinkrose: Please don't post code in comments. Edit your question and add it there - but it seems like a new question, so perhaps post a new one.
0

YOU HAVE TO CLOSE EVERY SINGLE OBJECT THAT YOU OPEN. Andre underscored the issue. Look very closely at your code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.