Results 1 to 5 of 5

Thread: VBA To Close Workbook Based On Cell Value Change And Open New Workbook

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0

    VBA To Close Workbook Based On Cell Value Change And Open New Workbook

    I use validation dropdown list to open some subworkbooks from this Main workbook “Main.xls”, i only need one subworkbook opened, if user opening a new subworkbook, the one that is already opened should be closed, what is the codes for this event? thanks for any help


    Code:
    Sub Open_Doc()
    
         Application.ScreenUpdating = False
    
         Workbooks.Open Filename _
            :=Sheets("Sheet1").Range("B2").Value & Sheets("Sheet1").Range("C2").Value
    
         Workbooks("Main.xls").Activate
        
         Application.ScreenUpdating = True
    
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("C2")) Is Nothing Then
        Select Case Range("C2")
            Case "Doc_01.xls": Open_Doc
            Case "Doc_02.xls": Open_Doc
            Case "Doc_03.xls": Open_Doc
            Case "Doc_04.xls": Open_Doc
            Case "Doc_05.xls": Open_Doc
        End Select
    End If
    End Sub
    Last edited by Excel Fox; 04-10-2014 at 08:07 PM. Reason: Corrected Code Tags

Similar Threads

  1. Replies: 6
    Last Post: 09-07-2013, 03:40 PM
  2. Replies: 6
    Last Post: 08-25-2013, 12:35 PM
  3. VBA Code to Open Workbook and copy data
    By Howardc in forum Excel Help
    Replies: 16
    Last Post: 08-15-2012, 06:58 PM
  4. Replies: 2
    Last Post: 12-12-2011, 01:51 PM
  5. Timer to close excel workbook
    By leopaulc in forum Excel Help
    Replies: 5
    Last Post: 10-24-2011, 12:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •