Userform Populated with range from another excel file

jsabo

New Member
Joined
May 27, 2014
Messages
17
Hello,

Trying to automate the generation of templates in Word. I am creating a userform with combo boxes and I would like the combo boxes to be populated from ranges in a separate excel file, which will be closed once the variables are assigned to the ranges (without the user ever seeing the excel file).

First, the below runs from a button on a ribbon:

Code:
Sub GenerateLetter()'
' GenerateLetter Macro
'
'
   


UserInput.Show




End Sub

Then, the UserInput form is shown and the code for its initialization looks like:

Code:
Private Sub UserForm_Initialize()


    Dim oExcel As Object
    Dim oWB As Object
    Dim SCNumberRange As Range
    Dim LastRow As Long
    
    Set oExcel = CreateObject("Excel.Application")
    Set oWB = oExcel.Workbooks.Open("C:\Users\jsabo\Documents\Letter Generator\Admin\Subcontract_List.xlsx")
    oExcel.Visible = True
    
    With oWB


        LastRow = .ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Set SCNumberRange = oWB.Sheets("Data").Range("A2:A" & LastRow)
        
    End With
    
End Sub
I get a runtime 424 'Object Required' error. Currently, both the userform and the module are both under the "Normal" project. Any ideas?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,225,681
Messages
6,186,411
Members
453,352
Latest member
OrionF

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