+ Reply to Thread
Results 1 to 5 of 5

Open/close files and copy and paste problem

  1. #1
    Registered User
    Join Date
    01-10-2011
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    9

    Open/close files and copy and paste problem

    Newbie here. Below is my code. Attempting to parse through all the tabs in the active worksheet and the ones starting with "x's" I want to pull the data from columns D and E and put into a new .csv file. I have been sucessful but only if the csv files already exists. If I create the file then I am unable to paste into it. I've even attempted to create it, and then close it just to reopen it to no avail. Honestly, VBA with excel is the most agravating coding I have ever experienced. Thanks for any help. Todd
    The error it throws is "PasteSpecial Method of Range class failed"

    Please Login or Register  to view this content.
    Last edited by kb9nvh; 01-11-2011 at 10:45 AM.

  2. #2
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Open/close files and copy and paste problem

    Hi Todd;

    At first glance I don't see a problem. What is the error message that you get when it crashes?
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  3. #3
    Registered User
    Join Date
    01-10-2011
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Open/close files and copy and paste problem

    Thanks for the response...
    I'm using excel 2007 just so you know.
    I'll run it tomorrow when I'm back at work and post the error message. I forget exactly what the complaint is. If you care to recreate the issue, just make a workbook with a few worksheets, name one with an "x" as the first character. add some data to columns D and E. This code is suppose to parse through each tab and when it finds a tab with a "x" then it copies the data that exists in columns D and E. Then the code should create a .csv file name derived from the tab name and insert the column data into the first two columns. This code all works fined if the .csv file already exists (and I eliminate the two lines that create the file). When I create the file on the fly and then close it. Then Reopen it it runs up until the Paste command where it bombs with an error (I cant remember which one but its something about a method not supported I think.

    For the life of me, I think I should just be able to move those columns right from one workbook to another without all the copy and pasting but I'm too stupid to understand the excel VBA grand plan and it seems like nothing works twice in the way you want it to. '

    I'll post again tomorrow if the snow allows me to get into work.



    Quote Originally Posted by foxguy View Post
    Hi Todd;

    At first glance I don't see a problem. What is the error message that you get when it crashes?

  4. #4
    Registered User
    Join Date
    01-10-2011
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Open/close files and copy and paste problem

    SOLVED: Moved the "copy" portion after the file create as the create new file wipes out the data in the paste buffer.

    The error it throws is "PasteSpecial Method of Range class failed" . If the file already exsists and I just open it then the paste functions as expected.

    I did modify this .add.saveas to include the .csv fileformat as I found that it was just saving it as the default type but with a false extension.

    OK, someone here suggested that creating the new file would wipe out all of my "copy" data. That was the problem is there was not data to paste.


    Can someone suggest code that will eliminate the copy/paste step and just allow me to directly assign the data from one workbook to another? I've tried it but always with errors that I'm at a loss to understand.

    Thanks for the hand holding..
    Last edited by kb9nvh; 01-11-2011 at 10:42 AM.

  5. #5
    Registered User
    Join Date
    01-10-2011
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Open/close files and copy and paste problem

    Here's the working version for anyone who cares..haha

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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