Popup with selectable list of open workbooks

DThompson89

New Member
Joined
Dec 15, 2023
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
I am trying to figure out how to get a popup with a list of open workbooks that is selectable, so that the selected workbook can be used to copy data into the original workbook containing the macro. I was able to do something similar with the worksheets, see the example below. Is it possible to do the same with all open workbooks? I've tried it a bunch of different ways, and keep getting errors.

Sub Example()

Dim ws As Worksheet
Application.CommandBars("Workbook Tabs").ShowPopup
Set ws = ActiveSheet

End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
 
Upvote 0
Solution
An alternative to the link :

Create a UserForm called OpenFiles.
Put on the UserForm the following:
• A list box (ListBox1)
• A button (CommandButton1) with the caption ‘OK’
• A button (CommandButton2) with the caption ‘Close’
• A button (CommandButton3) with the caption ‘Refresh’

Put the following macros in the UserForm module:
VBA Code:
Option Explicit
Dim x#, f#, pth As Range, wb$

'Close button
Private Sub CommandButton2_Click()
Unload OpenFiles
End Sub

'OK Button
Private Sub CommandButton1_Click()
Call Activate_File
End Sub

'Refresh Button
Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
Call Open_Files
End Sub

'List Box
Private Sub ListBox1_DblClick (ByVal Cancel As MSForms.ReturnBoolean)
Call Activate_File
End Sub
Sub Activate_File()
x = 0
For f = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(f) Then
        If ListBox1.Value <> "" Then
            x = x + 1
            Windows(ListBox1.Value).Activate
            Application.WindowState = xlNormal
            ListBox1.Selected(f) = False
            Exit For
        End If
    End If
Next
If x = 0 Then MsgBox "You have not selected a file to activate"
End Sub

To display the UserForm run this macro from a normal module:
VBA Code:
Sub Open_Files()
Dim checkCell As Range, wb As Workbook, maxW#

Application.ScreenUpdating = False
Unload OpenFiles

For Each wb In Workbooks
    If Windows(wb.Name).Visible Then _
        OpenFiles.ListBox1.AddItem wb.Name
Next
OpenFiles.Show vbModeless

ActiveWindow.WindowState = xlNormal
OpenFiles.Top = 563
OpenFiles.Left = 1452 - 295

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you! This worked for what I needed.
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,313
Members
453,032
Latest member
Pauh

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