LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default How do you program so that Workbook B cannot be open unless Workbook A is open? Plus I need to validation

Assume the names of workbook are "A.xls" and "B.xls".
Assume for validation, you want to check value in cell F10 in Sheet1 of
A.xls.

Then in "B.xls" , add following code in Thisworrkbook - Workbook_Open
procedu

Private Sub Workbook_Open()
On Error Resume Next
If Workbooks("A.xls").Parent Is Nothing Then
MsgBox "Workbook 'A.xls', is not open. Therefore this" & _
"workbook will close"
ThisWorkbook.Close SaveChanges:=False
Exit Sub
End If

If Workbooks("A.xls").Sheet1.Range("F10").Value = _
"whatever value you want to check" Then
'Your further code if the value is correct
Else
'your code if the value is not correct
End If

End Sub

Another alternative could be instead of closing workbook B.xls, if workbook
A.xls is not open
you can make the code to open 'A.xls'. If you wish to do this the code will
be as under, assuming
A.xls is in C:\My Documents

Private Sub Workbook_Open()
On Error Resume Next
If Workbooks("A.xls").Parent Is Nothing Then
Workbooks.Open Filename:="C:\My Documents\A.xls"
End If
If Workbooks("A.xls").Parent Is Nothing Then Exit Sub
If Workbooks("A.xls").Sheet1.Range("F10").Value = _
"whatever value you want to check" Then
'Your further code if the value is correct
Else
'your code if the value is not correct
End If

End Sub




"Marcello do Guzman" wrote in message
...
so that Workbook B would check for a certain value in a worksheet in
Workbook A. If you have the VBA code for this please let me know.
Thanks in advance.


TooShyNiceGuy

You can post answer here or send me email at:






 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to: Open closed workbook/Search data tables/Return data to open workbook Hugh Adams Excel Discussion (Misc queries) 0 August 18th 10 02:04 PM
how do i open a data workbook when i open a timesheet workbook [email protected] uk Excel Discussion (Misc queries) 2 January 4th 09 04:50 PM
Keeping program open even when closing workbook Bob Excel Discussion (Misc queries) 3 April 25th 08 07:55 PM
Why open more than one Excel program to see more than one workbook stevemalee[_2_] Excel Discussion (Misc queries) 3 June 11th 07 03:09 PM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM


All times are GMT +1. The time now is 08:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"