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:
Thanks for any help
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