I am ok on my VBA, I had an old code that was great for exporting to Excel on my C: drive and formatting the excel sheet.
It has never done this before, but all of a sudden, the code is making 2 files. The desired *.xlsx and a backup*.xlk file. While the backup file doesn't accumulate when I export the file over and over...it is annoying and ticking me off.:banghead:. How do I stop this? Below is my code. TIA for all your help.
Private Sub Command7_Click()
'Kills/Deletes The old file
Dim strFile
strFile = C Drive and file \Active-Pred Comparison-2014-.xlsx"
If Dir(strFile) <> vbNullString Then
Kill (strFile)
End If
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acExport, 10, "07a_Activity-Pred_Complete", " C Drive and file \Active-Pred Comparison-2014-.xlsx"
Set oApp = CreateObject("Excel.Application")
oApp.Workbooks.Open FileName:= C Drive and file \Active-Pred Comparison-2014-.xlsx"
oApp.Visible = False
'oApp.Sheets("07a_Activity-Pred_Complete").Select
'oApp.Sheets("07a_Activity-Pred_Complete").Name = "Activity-Pred Report"
oApp.Range("A1").Select
LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
oApp.Range("A1").Select
oApp.ActiveSheet.Range("A1:H" & LastRow).Sort Key1:=ActiveSheet.Columns("E"), Order1:=xlAscending, Header:=xlYes
oApp.ActiveSheet.Range("A1:H" & LastRow).Sort Key1:=ActiveSheet.Columns("B"), Order1:=xlAscending, Header:=xlYes
'oApp.ActiveCell.Offset(1).EntireRow.Insert
oApp.Range("A1:H20000").Font.Name = "Arial"
oApp.Range("A1:H20000").Font.Size = 8
oApp.Range("A1:H1").Interior.Color = RGB(141, 180, 226)
'oApp.Range("A2:H2").Interior.Color = RGB(255, 255, 153)
oApp.Range("A1:H1").Font.Bold = True
'oApp.Range("A2:H2").AutoFilter
oApp.Range("A1").Select
oApp.Range("2:2").Select
oApp.ActiveWindow.FreezePanes = True
oApp.Columns("A:H").EntireColumn.AutoFit
oApp.Range("A1:H20000").HorizontalAlignment = xlCenter
oApp.Range("A1:H1").Borders(xlEdgeBottom).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlEdgeBottom).Weight = xlThin
oApp.Range("A1:H1").Borders(xlEdgeLeft).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlEdgeLeft).Weight = xlThin
oApp.Range("A1:H1").Borders(xlEdgeRight).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlEdgeRight).Weight = xlThin
oApp.Range("A1:H1").Borders(xlEdgeTop).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlEdgeTop).Weight = xlThin
oApp.Range("A1:H1").Borders(xlInsideVertical).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlInsideVertical).Weight = xlThin
oApp.Range("A1:H1").Borders(xlInsideHorizontal).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlInsideHorizontal).Weight = xlThin
oApp.Range("A1").Select
oApp.DisplayAlerts = False
oApp.ActiveWorkbook.Save
MsgBox "Export Complete"
oApp.Quit
End Sub
It has never done this before, but all of a sudden, the code is making 2 files. The desired *.xlsx and a backup*.xlk file. While the backup file doesn't accumulate when I export the file over and over...it is annoying and ticking me off.:banghead:. How do I stop this? Below is my code. TIA for all your help.
Private Sub Command7_Click()
'Kills/Deletes The old file
Dim strFile
strFile = C Drive and file \Active-Pred Comparison-2014-.xlsx"
If Dir(strFile) <> vbNullString Then
Kill (strFile)
End If
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acExport, 10, "07a_Activity-Pred_Complete", " C Drive and file \Active-Pred Comparison-2014-.xlsx"
Set oApp = CreateObject("Excel.Application")
oApp.Workbooks.Open FileName:= C Drive and file \Active-Pred Comparison-2014-.xlsx"
oApp.Visible = False
'oApp.Sheets("07a_Activity-Pred_Complete").Select
'oApp.Sheets("07a_Activity-Pred_Complete").Name = "Activity-Pred Report"
oApp.Range("A1").Select
LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
oApp.Range("A1").Select
oApp.ActiveSheet.Range("A1:H" & LastRow).Sort Key1:=ActiveSheet.Columns("E"), Order1:=xlAscending, Header:=xlYes
oApp.ActiveSheet.Range("A1:H" & LastRow).Sort Key1:=ActiveSheet.Columns("B"), Order1:=xlAscending, Header:=xlYes
'oApp.ActiveCell.Offset(1).EntireRow.Insert
oApp.Range("A1:H20000").Font.Name = "Arial"
oApp.Range("A1:H20000").Font.Size = 8
oApp.Range("A1:H1").Interior.Color = RGB(141, 180, 226)
'oApp.Range("A2:H2").Interior.Color = RGB(255, 255, 153)
oApp.Range("A1:H1").Font.Bold = True
'oApp.Range("A2:H2").AutoFilter
oApp.Range("A1").Select
oApp.Range("2:2").Select
oApp.ActiveWindow.FreezePanes = True
oApp.Columns("A:H").EntireColumn.AutoFit
oApp.Range("A1:H20000").HorizontalAlignment = xlCenter
oApp.Range("A1:H1").Borders(xlEdgeBottom).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlEdgeBottom).Weight = xlThin
oApp.Range("A1:H1").Borders(xlEdgeLeft).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlEdgeLeft).Weight = xlThin
oApp.Range("A1:H1").Borders(xlEdgeRight).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlEdgeRight).Weight = xlThin
oApp.Range("A1:H1").Borders(xlEdgeTop).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlEdgeTop).Weight = xlThin
oApp.Range("A1:H1").Borders(xlInsideVertical).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlInsideVertical).Weight = xlThin
oApp.Range("A1:H1").Borders(xlInsideHorizontal).LineStyle = xlContinuous
oApp.Range("A1:H1").Borders(xlInsideHorizontal).Weight = xlThin
oApp.Range("A1").Select
oApp.DisplayAlerts = False
oApp.ActiveWorkbook.Save
MsgBox "Export Complete"
oApp.Quit
End Sub