Code to open external workbook

Closed
G - 24 Nov 2010 à 11:03
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 30 Nov 2010 à 10:25
Hello,
I have searched all over for this one and can't seem to find it... I am wanting to open a workbook if an age entry is below 12. I am trying to create a macro in my main workbook to open 'Master Kids 2010.xlsm'.
Any ideas please - I'm a complete noob at this. Using Office 2007 on XP SP3.
Thanks in advance...

Traveller_1

1 response

TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
30 Nov 2010 à 10:25
Hi G,

OK, so you have an open workbook where you input someone's age in cell A1.
Whenever the entered age drops below 12 you want to open a specific workbook. If this is correct use the following code, which you implement in the sheet where the age is entered (right click on sheets tab and select "view code"):

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
If Range("A1") < 12 Then Workbooks.Open Filename:="EnterYourFilenamesFullPathLike: C:\Excel\Master Kids 2010.xlsm"
End Sub

Let me know how this works for you.

Best regards,
Trowa