Can you open an external wb, retrieve a drop down menu then close it

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a wb with a drop down menu that correctly references an external wb to get the list but the external wb needs to be open to do so. It is going to be used by more than one person and will be stored on a server. Is there a way to have the external wb open when the cell with the list is selected, retrieve the drop down list then close it? I can't have it open all the time as it stores additional information that could be added to by another user and might be accidentally saved over.

Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I thought of a possible solution but I don't know if it will work or how to get it to work.

The idea was that I put code into the change event for the worksheet:
Code:
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("B7")) Is Nothing Then
            Workbooks.Open ThisWorkbook.Path & "\" & "Client_list.xlsm"
        End If
    End If

The client_list file is stored in the same folder and the drop down list is in B7, this code wouldn't open the file upon selection of B7. Could someone help me with the vba please?
 
Upvote 0
Try this combination of event macros

Code:
[COLOR=#006400]Private Sub Worksheet_SelectionChange[/COLOR](ByVal Target As Range)
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("B7")) Is Nothing Then OpenClientList
    End If
[COLOR=#006400]End Sub[/COLOR]
[COLOR=#006400]Private Sub Worksheet_Chang[/COLOR]e(ByVal Target As Range)
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("B7")) Is Nothing Then CloseClientList
    End If
[COLOR=#006400]End Sub[/COLOR]
[COLOR=#006400]Private Sub Worksheet_BeforeRightClick[/COLOR](ByVal Target As Range, Cancel As Boolean)
    If Selection.Count = 1 Then
        If Not Intersect(Target, Range("B7")) Is Nothing Then
            Cancel = True
            CloseClientList
        End If
    End If
[COLOR=#006400]End Sub[/COLOR]
[COLOR=#006400]Private Sub OpenClientList[/COLOR]()
    On Error Resume Next
    Workbooks.Open ThisWorkbook.Path & "\" & "Client_list.xlsm"
    Me.Parent.Activate
[COLOR=#006400]End Sub[/COLOR]
[COLOR=#006400]Private Sub CloseClientList[/COLOR]()
    On Error Resume Next
    Application.ScreenUpdating = False
    Workbooks("Client_list.xlsm").Close False
[COLOR=#006400]End Sub[/COLOR]

Explanation
Selecting the cell opens the workbook
Changing the value closes the workbook
Before Right Click event prevents right-clickng the cell triggering the selection macro and gives a method to close the workbook if value in cell is not amended
I prefer event macros to be "clean" of detail
- may also want to use them for other things later and they become very cluttered
- hence separate macros for opening and cloing the workbooks
On Error Resume Next prevents VBA failing if workbook not found


Q Is the data validation list derived from a static range of cells in Client_List ?
 
Last edited:
Upvote 0
If the data validation list is derived from a static range of cells in Client_List ...
... consider using a formula to get the values from Client_List as illustrated below

Excel 2016 (Windows) 32 bit
A
B
1
Formula in A2 copied down
2
Ant ='C:\Folder\SubFolder\[Client_list.xlsm]MySheet'!$A1
3
Cat
4
Dog
5
Mouse
6
Hampster
7
Cow
8
Sheep
9
Lamb
10
Goat
11
Elephant
Sheet: Sheet2
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,519
Members
448,968
Latest member
Ajax40

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