Closing another workbook

Spikenaylor

Board Regular
Joined
Apr 14, 2013
Messages
115
Office Version
  1. 365
Platform
  1. Windows
Hi there,
I am using data validation linked to a list in another workbook, both need to be open in the same instance of excel and everything works fine.
The source spreadsheet opens up and is hidden as noone needs to see it.

I can save my spreadsheet that I am entering data on , but then want to close both workbooks together when clicking X

however only my data entry spreqdsheet closes and it asks me if I want to save the other workbook before closing.
i have tried various methods but unsucessfuly.
Can anyone provide a clue..

Many thanks in advance
code is shown

Code:
Private Sub Workbook_Open() 'opens automatically with your Excel file
Application.ScreenUpdating = False
    Workbooks.Open Filename:="F:\Controlled Systems\Main Strain List\Strains Spreadsheet.xlsx", UpdateLinks:=True, ReadOnly:=True
    ActiveWindow.Visible = False
    Application.ScreenUpdating = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ' I need to get a command here to close the Strains Spreadsheet with out saving.
    
    Application.ScreenUpdating = False
    
    Workbooks.Close("F:\Controlled Systems\Main Strain List\Strains Spreadsheet.xlsx").Saved = False ' this not working
    Workbooks("F:\Controlled Systems\Main Strain List\Strains Spreadsheet.xlsx").Close = True ' this not working
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this.
Code:
Workbooks("Strains Spreadsheet.xlsx").Close
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top