title: Can you call a module from a userform whose variable is declared from a combo box?
body: <p>I created a userform sub that will allow the user to choose from the open workbook to use as the reference workbook using a combo box.  My current script is returning an error that <code>workbooks(wb)</code> is not defined - I assume this is because the variable is defined in two different modules and the combo box is not in the module being called. Ideally would like to use the userform below </p>
  
  <pre><code>Private Sub Go_Click()
  
   If ComboBox1.ListIndex = -1 Then
          MsgBox "Please select a workbook name and try again"
          Exit Sub
      End If
  
    Dim wb As Variant
  
    wb = ComboBox1.List(ComboBox1.ListIndex)
  
    Call GenerateReportUserForm
  
  End Sub
  </code></pre>
  
  <p>To call this sub: </p>
  
  <pre><code>Sub newMacro()
  
  Dim copyNames As Range, pasteNames As Range, copyAmounts As Range, pasteAmounts As Range, copyDates As Range, pasteDates As Range, _
  copyPayment As Range, pastePayment As Range
  
  '   For cheques only
  
  Set copyNames = Workbooks(wb).Worksheets(2).Columns("F")
  Set copyAmounts = Workbooks(wb).Worksheets(2).Columns("AR")
  Set copyDates = Workbooks(wb).Worksheets(2).Columns("AI")
  Set copyPayment = Workbooks(wb).Worksheets(2).Columns("AJ")
  
  Set pasteNames = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("A")
  Set pasteAmounts = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("C")
  Set pasteDates = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("D")
  Set pastePayment = Workbooks("VBA Workbook.xlsm").Worksheets(1).Columns("E")
  
  copyNames.Copy Destination:=pasteNames
  copyAmounts.Copy Destination:=pasteAmounts
  copyDates.Copy Destination:=pasteDates
  copyPayment.Copy Destination:=pastePayment
  
  End sub
  </code></pre>
  
  <p>Thanks! </p>