Richard1982
New Member
- Joined
- Jul 6, 2022
- Messages
- 11
- Office Version
- 365
- Platform
- Windows
I have a small section of VBA code (as part of a larger macro) which takes some of the pages of the report I'm working on and saves them to a new file.
This copies the pages I want, inserts them in after 'sheet1' (By default my excel starts all workbooks with just one sheet), then deletes 'sheet1'. It then saves the file to the location of my choice. As is it works absolutely fine, no problems. The only thing that I'd like to improve is that the file is opened up on the screen and I need to close it down. Is there any way to avoid this and just have it save the file without showing me?
I'm still learning so I apologise if this code isn't the most elegant of solutions! Any help would be greatly appreciated
Richard
VBA Code:
Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Worksheets(Array("Page 1", "Page 3", "Page 4", "Page 6", "Page 7")).Copy Before:=wb.Sheets(1)
'This bit deletes Sheet 1 which is there by default
wb.Sheets("Sheet1").Delete
wb.SaveAs "Z:\Reporting\Report.xlsx"
This copies the pages I want, inserts them in after 'sheet1' (By default my excel starts all workbooks with just one sheet), then deletes 'sheet1'. It then saves the file to the location of my choice. As is it works absolutely fine, no problems. The only thing that I'd like to improve is that the file is opened up on the screen and I need to close it down. Is there any way to avoid this and just have it save the file without showing me?
I'm still learning so I apologise if this code isn't the most elegant of solutions! Any help would be greatly appreciated
Richard