I am stumped and need help.
From an Access command button (using VBA) I am opening 2 different existing workbooks. The first workbook1 that opens I add information to some of the cells then save the spreadsheet as a different name (new_workbook1). The second workbook2 is opened and I simply need to rename (and save) as new_workbook2. I need both the renamed new_workbooks to remain open and the original 2 workbooks to close. My code works except that somehow the original workbooks remain open in the background and the new renamed and saved workbooks close. Here is my code:
Private Sub Select_PI_file_Click()
Dim objXLApp As Object
Dim objXLBook As Object
Set objXLApp = CreateObject("Excel.Application")
Set objXLBook = objXLApp.Workbooks.Open("c:\workbook1")
With objXLApp
Workbooks.Open ("c:\workbook1")
Sheets.Select
Sheets(1).Activate
Range("C35").Select
Selection.ClearContents
Range("C3").Select
ActiveCell.FormulaR1C1 = "new text added"
End With
ActiveWorkbook.SaveAs ("c:\new_workbook1")
Set objXLBook = objXLApp.Workbooks.Open("c:\workbook2")
ActiveWorkbook.SaveAs ("c:\new_workbook2")
End Sub
From an Access command button (using VBA) I am opening 2 different existing workbooks. The first workbook1 that opens I add information to some of the cells then save the spreadsheet as a different name (new_workbook1). The second workbook2 is opened and I simply need to rename (and save) as new_workbook2. I need both the renamed new_workbooks to remain open and the original 2 workbooks to close. My code works except that somehow the original workbooks remain open in the background and the new renamed and saved workbooks close. Here is my code:
Private Sub Select_PI_file_Click()
Dim objXLApp As Object
Dim objXLBook As Object
Set objXLApp = CreateObject("Excel.Application")
Set objXLBook = objXLApp.Workbooks.Open("c:\workbook1")
With objXLApp
Workbooks.Open ("c:\workbook1")
Sheets.Select
Sheets(1).Activate
Range("C35").Select
Selection.ClearContents
Range("C3").Select
ActiveCell.FormulaR1C1 = "new text added"
End With
ActiveWorkbook.SaveAs ("c:\new_workbook1")
Set objXLBook = objXLApp.Workbooks.Open("c:\workbook2")
ActiveWorkbook.SaveAs ("c:\new_workbook2")
End Sub