(don't forget to add the reference)
try:
Code:With OpenFileDialog1 .Filter = "XLS files (*.xls)|*.xls|All files (*.*)|*.*" .FilterIndex = 1 .Title = "Open Template" .ShowDialog() '<-first mistake End With If OpenFileDialog1.FileName <> "" Then FilePath = OpenFileDialog1.FileName Dim xlapp = CType(CreateObject("Excel.Application"), Excel.Application) Dim xlbook As Excel.Workbook '<-Better for writting code Dim xlsheet As Excel.Worksheet xlbook = xlapp.Workbooks.Open(FilePath) xlsheet = CType(xlbook.Worksheets(1), Excel.Worksheet) customername(1) = xlsheet.Cells(3, 2).value '<-explicit.value customeraddress(1) = xlsheet.Cells(3, 3).value customerphone(1) = xlsheet.Cells(3, 4).value xlsheet = Nothing xlbook.close(False) xlbook = Nothing xlapp = Nothing End If




Reply With Quote