rohanmalhotra
New Member
- Joined
- May 4, 2010
- Messages
- 29
Hi all
i am preparing a template in word userform. In the template, i want the senders name to come up automatically, therefore, i have created an excel sheet which has the list of staff members with their employee id's (as they login to the system with there employee id's and that will be picked up). i have written a code but it is giving me run time error 13.
Can anyone of you please help.
Many Thanks
i am preparing a template in word userform. In the template, i want the senders name to come up automatically, therefore, i have created an excel sheet which has the list of staff members with their employee id's (as they login to the system with there employee id's and that will be picked up). i have written a code but it is giving me run time error 13.
HTML:
Sub GetExcelData()
Dim objExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim ws As Excel.Worksheet
Dim myRange As Range
Dim UserName As String
Dim rs As Variant
Set objExcel = CreateObject("Excel.Application")
Set wbk = objExcel.Workbooks.Open("M:\Phones\Management Information\Projects\Staff.xls")
Set ws = wbk.Worksheets("Staff")
UserName = Me.txtID.Value
myRange = ws.Range("A1:B500")
rs = wbk.Application.WorksheetFunction.VLookup("UserName", "myRange", 2, False)
End Sub
Can anyone of you please help.
Many Thanks