I have the following code and it works about half of the time. It grabs an excel file from access and edits it, then I will write another part to import the excel data to a table. There seems to be a problem with this code not actually completely closing the excel file. It will often not load after I run this code. Sometimes I get a runtime error 9 and it will highlight the part that I have put in red below. I am not sure this is even needed it may be redundant but if I take out the activate workbook part the activate sheet part below it gets flagged by the debugger. Any help would be appreciated. I am really new to this. Thanks
Sub UpdateBaker()
'Set wb = Workbooks.Open(FileName:="C:\Documents and Settings\john.turrin\Desktop\Anext.xlsm")
'Application.ScreenUpdating = False
Dim appXL As Excel.Application
Dim wbk As Excel.Workbook
Set appXL = New Excel.Application
Set wbk = appXL.Workbooks.Open("C:\Documents and Settings\john.turrin\Desktop\Anext.xlsm")
Workbooks("Anext.xlsm").Activate
Sheets("Sheet1").Select
Range("A2").Select
ActiveCell.FormulaR1C1 = "Well#"
Range("B2").Select
ActiveCell.FormulaR1C1 = "MCF"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Psi T"
Range("D2").Select
ActiveCell.FormulaR1C1 = "Psi C"
Range("E2").Select
ActiveCell.FormulaR1C1 = "Date"
Range("F2").Select
ActiveCell.FormulaR1C1 = "Date Uploaded"
Range("E3").Select
ActiveCell.FormulaR1C1 = "1/1/1980"
Range("E4").Select
ActiveCell.FormulaR1C1 = "1/1/1980"
Range("E5").Select
ActiveCell.FormulaR1C1 = "1/1/1980"
Range("E3:E5").Select
Selection.AutoFill Destination:=Range("E3:E886")
Range("E3:E886").Select
Range("F3").Select
ActiveCell.Value = Date
Range("F4").Select
ActiveCell.Value = Date
Range("F5").Select
ActiveCell.Value = Date
Range("F3:F5").Select
Selection.AutoFill Destination:=Range("F3:F886")
Range("E3:F3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "m/d/yyyy"
Range("H2").Select
wbk.Close
appXL.Quit
Set appXL = Nothing
Set wbk = Nothing
End Sub
Sub UpdateBaker()
'Set wb = Workbooks.Open(FileName:="C:\Documents and Settings\john.turrin\Desktop\Anext.xlsm")
'Application.ScreenUpdating = False
Dim appXL As Excel.Application
Dim wbk As Excel.Workbook
Set appXL = New Excel.Application
Set wbk = appXL.Workbooks.Open("C:\Documents and Settings\john.turrin\Desktop\Anext.xlsm")
Workbooks("Anext.xlsm").Activate
Sheets("Sheet1").Select
Range("A2").Select
ActiveCell.FormulaR1C1 = "Well#"
Range("B2").Select
ActiveCell.FormulaR1C1 = "MCF"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Psi T"
Range("D2").Select
ActiveCell.FormulaR1C1 = "Psi C"
Range("E2").Select
ActiveCell.FormulaR1C1 = "Date"
Range("F2").Select
ActiveCell.FormulaR1C1 = "Date Uploaded"
Range("E3").Select
ActiveCell.FormulaR1C1 = "1/1/1980"
Range("E4").Select
ActiveCell.FormulaR1C1 = "1/1/1980"
Range("E5").Select
ActiveCell.FormulaR1C1 = "1/1/1980"
Range("E3:E5").Select
Selection.AutoFill Destination:=Range("E3:E886")
Range("E3:E886").Select
Range("F3").Select
ActiveCell.Value = Date
Range("F4").Select
ActiveCell.Value = Date
Range("F5").Select
ActiveCell.Value = Date
Range("F3:F5").Select
Selection.AutoFill Destination:=Range("F3:F886")
Range("E3:F3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "m/d/yyyy"
Range("H2").Select
wbk.Close
appXL.Quit
Set appXL = Nothing
Set wbk = Nothing
End Sub