Results 1 to 3 of 3

Thread: Open Excel Sheet , Runtime Error 91

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    32

    Open Excel Sheet , Runtime Error 91

    Hello,

    I am Trying to open a excel sheet ,the name of excel sheet i am assigning in the text box, i need to open the sheet " Employee Attendence" and write in the cells(1,1) ="hai"

    i have written the below code

    Code:
    Private Sub Command1_Click(Index As Integer)
       Dim vari As String
      Dim uppxl    As Excel.Application
      Dim upxwb As Excel.Workbook
      Dim upxws As Excel.Worksheet
      vari = eempid.Text
    'error is here
      Set upxwb = uppxl.Workbooks.Open(App.Path & "\" & eempid.Text & ".xlsx")
    'error is here
     Set upxws = upxwb.Worksheets("Employee Attendence")
     With upxws
     .Cells(1, 1).Value = "hai"
      End With
     upxwb.Close SaveChanges:=True
     Set upxwb = Nothing
     uppxl.Quit
     Set uppxl = Nothing
            
    End Sub
    i am getting a runtime error 91 ,object variable or With block variable not set.

    kindly help

  2. #2

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Open Excel Sheet , Runtime Error 91

    Also be careful how you use App.Path because sometimes it may already end with a backslash. So do this instead.


    Code:
     Dim AppPath As String
    
        AppPath = App.Path
        If Right$(AppPath, 1) <> "\" Then 
            AppPath = AppPath + "\"
        End If 
    
         Set upxwb = uppxl.Workbooks.Open(AppPath & eempid.Text & ".xlsx")

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width