+ Reply to Thread
Results 1 to 4 of 4

Paste method fails when using template

  1. #1
    Registered User
    Join Date
    09-28-2011
    Location
    UK
    MS-Off Ver
    Office Home and Business 2016
    Posts
    14

    Paste method fails when using template

    Hi everyone,

    I'm having a macro problem in Excel 2003 and wondered if you would be able to help me please? I'm copying some data from a worksheet, creating a new worksheet then pasting the data I copied into the new sheet. My code for this is below which works perfectly:

    Please Login or Register  to view this content.
    However, the data needs quite a lot of formatting so I created a template with the required formatting and tried to use this template when creating the new worksheet. Here's the code I'm now trying to use:

    Please Login or Register  to view this content.
    The above copies the data, creates the new worksheet based on the template file, renames the sheet to whatever is in the variable "shname", selects "A11" but then fails when trying to paste the data. I get the error message "Paste method of worksheet class failed".

    Do you know why, just by changing the worksheet template, it would stop me from pasting the data into the new sheet?

    Thanks

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Paste method fails when using template

    You could try something like this:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    09-28-2011
    Location
    UK
    MS-Off Ver
    Office Home and Business 2016
    Posts
    14

    Re: Paste method fails when using template

    Thanks Dom,

    That works,although as a complete beginner I don't understand how or why

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Paste method fails when using template

    I'm guessing that the opening of the template is clearing the clipboard so performing the copy operation after adding the sheet gets round the problem. I never tested it though.

    Dom

+ 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