Advertisement
Guest User

Untitled

a guest
Apr 13th, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.92 KB | None | 0 0
  1. //форма
  2. Public SelectedWorkBook As workBook
  3.  
  4. Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  5. Dim SelectedName As String
  6.     SelectedName = Me.ListBox1.list(Me.ListBox1.ListIndex)
  7.     Set SelectedWorkBook = Workbooks(SelectedName)
  8.     Me.Hide
  9. End Sub
  10.  
  11. Private Sub UserForm_Initialize()
  12.     Set SelectedName = Nothing
  13.     Dim wb As workBook
  14.     For Each wb In Workbooks
  15.         If Not (wb.Name = ThisWorkbook.Name) Then
  16.             Me.ListBox1.AddItem wb.Name
  17.         End If
  18.     DoEvents
  19.     Next
  20. End Sub
  21.  
  22. //модуль
  23. Public Function GetWorkBookFromForm() As workBook
  24.     UserForm1.Show
  25.     If Not (UserForm1.SelectedWorkBook Is Nothing) Then
  26.         Set GetWorkBookFromForm = UserForm1.SelectedWorkBook
  27.     End If
  28.     Unload UserForm1
  29. End Function
  30.  
  31. Public Sub Test1()
  32.     Set targetBook = GetWorkBookFromForm()
  33.     If Not (targetBook Is Nothing) Then MsgBox targetBook.Name
  34. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement