UserFrom Initialise Problem...

nicolavision

New Member
Joined
Oct 21, 2004
Messages
31
Hi

I have a User Form that initalises when opened but I would like it to check if I file exist and if it does copy the information into the UserForm sheet.

How would I go about this?

Here's my current code:

Code:
Private Sub UserForm_Initialize()
Dim fso
Dim file As String

Sheet20.Visible = xlSheetVisible
Sheets("TypeOfExpense").Select
If Range("B2") = "Barclay Card" Then
Me.VehicleDetails.Visible = False
Else
Me.VehicleDetails.Visible = True
End If
Sheet20.Visible = xlSheetHidden


file = "C:\Employee.xls"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(file) Then
listbox1.RowSource = "NoEmployeeFile"



Else
With Me.listbox1

        Application.ScreenUpdating = False
        Set SourceWB = Workbooks.Open("C:\EmployeeDropDown", _
            False, True)
        ListItems = SourceWB.Worksheets(1).Range("A1:A500").Value
        SourceWB.Close False
        Set SourceWB = Nothing
        ListItems = Application.WorksheetFunction.Transpose(ListItems)
        For i = 1 To UBound(ListItems)
            .AddItem ListItems(i)
        Next i
        Application.ScreenUpdating = True
        txtEmployeeNo.SetFocus
End With
    
End If
End Sub

Thanks for any help
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,203,317
Messages
6,054,709
Members
444,742
Latest member
jmartin9247

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