+ Reply to Thread
Results 1 to 7 of 7

Thread: error 1004 : Application-defined or object-defined

  1. #1
    Registered User
    Join Date
    11-18-2011
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2003
    Posts
    4

    error 1004 : Application-defined or object-defined

    Hello Guys...

    I have a problem in this code :

    Dim oExcel As Object
    Dim objExlSht As Object
    Dim vas As Variant
    Dim Db1 As DAO.Database
    Dim Rs1 As DAO.Recordset
    Dim blnIsOpen As Boolean

    Set oExcel = CreateObject("Excel.Application")
    oExcel.Workbooks.Add
    Set objExlSht = oExcel.ActiveWorkbook.Sheets(1)

    'the error happens here.
    With Worksheets("Plan1").Range("A2")
    .CurrentRegion.Clear
    .CopyFromRecordset Rs1
    End With

    Could someone helpe me, please??

  2. #2
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: error 1004 : Application-defined or object-defined

    maybe you do not have sheet "Plan1" without file is hard to say what's going on.
    Last edited by tom1977; 11-18-2011 at 06:22 AM.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Registered User
    Join Date
    11-18-2011
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: error 1004 : Application-defined or object-defined

    Quote Originally Posted by tom1977 View Post
    maybe you do not have sheet "Plan1" without file is hard to say what's going on.



    Do you have any sugestion for to soulve this problem... another way for to do what I want to do?
    Last edited by Pititica; 11-18-2011 at 06:27 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: error 1004 : Application-defined or object-defined

    my suggestion is: attach the file with Your code (remove any confidential data of course)
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  5. #5
    Valued Forum Contributor
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Excel 2007 (Office 2007)
    Posts
    256

    Re: error 1004 : Application-defined or object-defined

    code tags make it easier for people to see and read the code - use [ code] without the space before and [ /code] without the space after


    
    
    Dim oExcel As Object
    Dim objExlSht As Object
    Dim vas As Variant
    Dim Db1 As DAO.Database
    Dim Rs1 As DAO.Recordset
    Dim blnIsOpen As Boolean
    
    Set oExcel = CreateObject("Excel.Application")
    oExcel.Workbooks.Add 
    Set objExlSht = oExcel.ActiveWorkbook.Sheets(1)
    
    'the error happens here.
    With Worksheets("Plan1").Range("A2")
    .CurrentRegion.Clear
    .CopyFromRecordset Rs1
    End With
    If genius is 99% perspiration - 1% inspiration, I know where I'm stuck

  6. #6
    Registered User
    Join Date
    11-18-2011
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: error 1004 : Application-defined or object-defined

    Quote Originally Posted by tom1977 View Post
    my suggestion is: attach the file with Your code (remove any confidential data of course)
    Understood...
    I don't know... The unique thing that i want to do is to show a excel sheet.. every time that press a buttom...
    But... The first time that I try.. I can, but if I show this sheet, close and press the buttom again... this problem happen...
    I've never used excel for this...

  7. #7
    Registered User
    Join Date
    11-18-2011
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: error 1004 : Application-defined or object-defined

    Quote Originally Posted by nigelog View Post
    code tags make it easier for people to see and read the code - use [ code] without the space before and [ /code] without the space after


    
    
    Dim oExcel As Object
    Dim objExlSht As Object
    Dim vas As Variant
    Dim Db1 As DAO.Database
    Dim Rs1 As DAO.Recordset
    Dim blnIsOpen As Boolean
    
    Set oExcel = CreateObject("Excel.Application")
    oExcel.Workbooks.Add 
    Set objExlSht = oExcel.ActiveWorkbook.Sheets(1)
    
    'the error happens here.
    With Worksheets("Plan1").Range("A2")
    .CurrentRegion.Clear
    .CopyFromRecordset Rs1
    End With

    Ok.. thank you for this....

    I don't know... what happens here... do you know other way that I can clean my sheet???

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0