+ Reply to Thread
Results 1 to 10 of 10

Trouble including paste special in macro

  1. #1
    Registered User
    Join Date
    06-12-2008
    Posts
    29

    Trouble including paste special in macro

    Hello,
    Wondering if there is anyway to include the paste formats and values into the below macro? Every time I try I get a Compile error, expected end of statement.

    Thanks

    Include This



    Please Login or Register  to view this content.


    Into this
    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Trouble including paste special in macro

    I think we can give you a better solution if you show all your code. You are showing the PasteSpecial without showing the Copy. Your syntax for PasteSpecial suggests it is inside a With but you don't show that. The Sub that you want to put this code into will need all of that.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-12-2008
    Posts
    29

    Re: Trouble including paste special in macro

    This is the entire code it is placed in a function module, I got it from this site: http://www.rondebruin.nl/win/s3/win024.htm
    It works fine I would just like to be able to do the paste and keep all the cell formatting from the file I copied from. Thanks


    Please Login or Register  to view this content.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble including paste special in macro

    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    06-12-2008
    Posts
    29

    Re: Trouble including paste special in macro

    yes, you are correct. I guess I did cross post. I didn't know the two boards were ran and monitored by the same folks. Sorry

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Trouble including paste special in macro

    They are not run by the same folks, but many of us have accounts on both. Both boards have rules against cross-posting.

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Trouble including paste special in macro

    Your question is still not clear. The code you posted does not have a copy anywhere. So what is it you want to paste, and where do you want to paste it?

  8. #8
    Registered User
    Join Date
    06-12-2008
    Posts
    29

    Re: Trouble including paste special in macro

    Thanks for sticking with me on this one.
    The way I understand it the option explicit code I have above I have to put in a Function module.
    The code that I have below I put into a regular module, which is copying/pulling the range A1:D10 from the spreadsheet called ToBeCopied.xlsx and importing/pasting or some kind of way bringing it into my current workbook and entering it in starting in cell A1.

    Hope that helps.

    Please Login or Register  to view this content.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Trouble including paste special in macro

    In reading through the code you posted in more detail, I see you are using an ADO connection to treat an Excel file as a database and retrieve data. This uses a SQL query. This is a fancy way to get data from a workbook without opening it. However, a SQL query returns data only, not formatting. So you cannot retrieve this data keeping the original formatting.

    I only know two ways to copy data from a closed workbook (this is one, the other uses an Excel4 macro call) and neither one retrieves formatting.

    Is there a particular reason that you don't want to open this workbook? If you can tolerate that, the code becomes much easier.

  10. #10
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: Trouble including paste special in macro

    Just to make a point to the poster...

    a SQL query returns data only, not formatting
    That was raised yesterday: http://www.ozgrid.com/forum/showthre...820#post768820

    That is exactly what I meant by "...some of those replies will be similar, if not identical. If that happens then someone has wasted their time".

    If you had the courtesy to follow forum etiquette you would have saved time, both for yourself and others.

+ 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. [SOLVED] Including a special line in my border's macro
    By coach.32 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2015, 05:46 PM
  2. Auto run macro from paste or paste special in to specific cell
    By Craig Muir in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2014, 10:00 AM
  3. [SOLVED] Simple copy and paste macro- Paste special help needed.
    By hernancrespo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2012, 07:02 AM
  4. Paste 'very' special macro
    By 1eyedjack in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-16-2011, 10:17 AM
  5. Macro to paste special
    By sandbach in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2010, 06:42 PM
  6. [SOLVED] Macro Special Paste - Value
    By Souriane in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-02-2005, 10:40 AM

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