+ Reply to Thread
Results 1 to 5 of 5

Runtime error 1004 application-defined object-defined

  1. #1
    Forum Contributor
    Join Date
    04-11-2017
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2010
    Posts
    110

    Runtime error 1004 application-defined object-defined

    Hi

    I'm getting a runtime error 1004 message on the following code when trying to execute the line in bold and I don't know why. I have checked to see if the macro is in module as opposed to a sheet and it is so that's not what is causing the problem. It works fine if I am in the sheet I am trying to execute the code on but fails if I don't have that sheet activated i.e. the first line of code also fails unless I am in that worksheet.

    New to VBA but I'm guessing it's something to do with the way I have declared Thisworkbook.

    Please Login or Register  to view this content.
    Any help appreciated.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Runtime error 1004 application-defined object-defined

    Try this.
    Please Login or Register  to view this content.
    Last edited by Norie; 06-13-2017 at 12:29 PM.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    04-11-2017
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2010
    Posts
    110

    Re: Runtime error 1004 application-defined object-defined

    Thank Norie. I'll try this in the morning & report back.

    Out of interest, why do we have to use 'with' and why separate statements for each line of code? It seems quite longwinded. Is there actually any benefit in declaring a variable for thisworkbook in this instance as opppsed to just using Workbooks(.....)? Apologies for so many questions, still trying to get to grips with thisworkbook and when to use it.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Runtime error 1004 application-defined object-defined

    You don't have to use With, here's an alternative way of doing things.
    Please Login or Register  to view this content.
    As for using variables, again you don't have to, but it might help to use variables with an appropriate names to help identify the workbooks you are working with.

    If you use Workbooks(...) instead of ThisWorkbook you would need to know the exact name of the workbook the code is in which probably won't change but you never know.

  5. #5
    Forum Contributor
    Join Date
    04-11-2017
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2010
    Posts
    110

    Re: Runtime error 1004 application-defined object-defined

    The above works Norie. Thanks for the info and your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 08-19-2015, 07:10 PM
  2. [SOLVED] Application defined or object defined error Runtime error 1004
    By avinkris in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2015, 10:38 PM
  3. [SOLVED] Runtime Error '1004' Application-defined or object-defined error
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 11:16 AM
  4. Replies: 0
    Last Post: 05-14-2012, 11:59 PM
  5. Runtime error '1004' Application-defined or object-defined error Comment
    By Willer in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-17-2011, 03:02 PM
  6. [SOLVED] RE: Runtime error 1004- application defined or object defined erro
    By Novice in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2006, 05:40 PM
  7. RE: Runtime error 1004- application defined or object defined erro
    By Jim Thomlinson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-06-2006, 05:35 PM

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.6.0 RC 1