+ Reply to Thread
Results 1 to 19 of 19

Copying to separate workbook marco not working

  1. #1
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Question Copying to separate workbook marco not working

    Hi,

    I have the below marco

    Please Login or Register  to view this content.
    Which basically copies the referenced cells from one workbook called "Web Update Request" to another workbook called "reports & updates log".

    I keep getting a runtime error 9 on this line
    Please Login or Register  to view this content.
    and im not sure why? The stranger thing is, is that it used to work just fine until yesterday.

    Any help would be great

    Thanks.




    EDIT, I figured it out. My PC settings had been changed to display file extensions, and thats what was missing.
    Last edited by Will_iam; 04-30-2013 at 09:11 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Copying to separate workbook marco not working

    can you attach the sheet?

  3. #3
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: Copying to separate workbook marco not working

    workbooks Attached.
    Attached Files Attached Files

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copying to separate workbook marco not working

    You need to put the file extension in this part of that line -
    Please Login or Register  to view this content.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: Copying to separate workbook marco not working

    Thanks for the reply, but that didnt work. Still get the same error.

    One other thing I thought i would mention, is that it does find the workbook in the first instance, so from this part,

    Please Login or Register  to view this content.
    As it opens the workbook, its just the actual copying of the cells.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Why aren't you using wbTarget in the copying code?
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: Copying to separate workbook marco not working

    Quote Originally Posted by Norie View Post
    Why aren't you using wbTarget in the copying code?
    Where do you mean?

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Copying to separate workbook marco not working

    you set the workbook to a variable and then reference it as workbooks("workbook name") again. You could use:
    Please Login or Register  to view this content.
    Note - Arlu's suggestion is correct, when you add the file extension to your code it works for me, so the changing the reference to wbTarget should also remove the error.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Wherever you have this,
    Please Login or Register  to view this content.
    replace it with wbTarget.

  10. #10
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: Copying to separate workbook marco not working

    Quote Originally Posted by yudlugar View Post
    you set the workbook to a variable and then reference it as workbooks("workbook name") again. You could use:
    Please Login or Register  to view this content.
    Note - Arlu's suggestion is correct, when you add the file extension to your code it works for me, so the changing the reference to wbTarget should also remove the error.
    Thanks for your help with this, your suggestion did resolve the issue with that line of code, but now it is just producing the same error on the next line

    Please Login or Register  to view this content.
    Which im assuming will mean it will be the same problem for the remaining lines as well. I have tried applying similar logic to it as you already mentioned, but to no avail.

    Im affraid my Vb skills arent to great.

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

    Re: Copying to separate workbook marco not working

    You need to replace all instances of this with wbTarget.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: Copying to separate workbook marco not working

    Quote Originally Posted by Norie View Post
    You need to replace all instances of this with wbTarget.
    Please Login or Register  to view this content.
    Thanks, I have tried that, and it doesnt make any difference?

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

    Re: Copying to separate workbook marco not working

    Can you post exactly what you did and tell us how it doesn't work?

    This is probably the easiest way to do it.
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: Copying to separate workbook marco not working

    This is what it looks like now.
    Please Login or Register  to view this content.
    I replaced the "Workbook" with wbTarget as you mentioned.

    It is still producing the runtime error 9, but now on a differnet line.
    Please Login or Register  to view this content.
    The "Reports & Updates Log" opens fine, it just then doesnt copy anything across, and just errors.

  15. #15
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Copying to separate workbook marco not working

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: Copying to separate workbook marco not working

    Quote Originally Posted by yudlugar View Post
    Please Login or Register  to view this content.
    Still produces the runtime error on the same line.....

    Seriously is VB just broken?

    What I really don't get is that, it worked fine last week. Then this week... nope, and im pretty sure I havent changed anything.

    I really appreciate the help though guys.

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

    Re: Copying to separate workbook marco not working

    Is this the workbook the code is in?
    Please Login or Register  to view this content.
    If it is replace it throughout the code with ThisWorkbook.
    Please Login or Register  to view this content.
    If it's not try replacing it with Workbooks("Web Update Request.xlsm")
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    08-06-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2007
    Posts
    62

    Re: Copying to separate workbook marco not working

    [QUOTE=Norie;3219610]Is this the workbook the code is in?
    QUOTE]

    Thanks for your help, the problem was the missing file extensions. But I figured it out just before you posted.

    But thanks anyway!

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

    Re: Copying to separate workbook marco not working

    The way to avoid that is not to use the workbook names to refer to them, use references.

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