+ Reply to Thread
Results 1 to 2 of 2

Copy paste

  1. #1
    Registered User
    Join Date
    07-11-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    2

    Copy paste

    Can't figure out the problem on the following code.. Everything works for sheet 1 properly but sheet 2 isn't copying and pasting. Also, even naming sheet 2 doesn't work. I have changed the names of the files to "---".

    Basically the goal here is to save the workbook into a different file name without macros on the new spreadsheet. At present time I have to manually copy and paste the second sheet in before saving again.

    PHP Code: 
    Sub SaveAs_xlsx()

    On Error Resume Next
     
        Dim WB1 
    As Workbook
        Dim WB2 
    As Workbook
        Dim newbook 
    As Workbook
        
        Set newbook 
    Workbooks.Add

        newbook
    .SaveAs "W:\------ " _
            
    Format(Date"yyyy-mm-dd"), 51
            
        Set WB1 
    Workbooks("--------.xlsm")
        
    Set WB2 Workbooks("------------- " Format(Date"yyyy-mm-dd") & ".xlsx")
        
        
    WB1.Activate
        Sheets
    (1).Range("A1:P1000").Select
        Selection
    .Copy WB2.Sheets(1).Cells(11)
        
        
    Sheets(2).Range("A1:P1000").Select
        Selection
    .Copy WB2.Sheets(2).Cells(11)
        
        
    WB2.Activate
        WB2
    .Sheets(1).Columns("A:P").Select
        WB2
    .Sheets(1).Columns("A:P").EntireColumn.AutoFit
        WB2
    .Sheets(2).Columns("A:P").Select
        WB2
    .Sheets(2).Columns("A:P").EntireColumn.AutoFit
        
        Sheets
    ("Sheet1").Select
        Sheets
    ("Sheet1").Name "-"
        
    Sheets("Sheet2").Select
        Sheets
    ("Sheet2").Name "not working"
        
        
    Sheets(1).Activate
        Sheets
    (2).Activate

        WB2
    .Save
        
        Call SetPrintFormatCAD
        Call SetPrintFormatUSD
        
        WB1
    .Activate
        
    End Sub 

  2. #2
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: Copy paste

    Please Login or Register  to view this content.
    To do it for me and help me it is 2 different things!
    Sorry for my english, blame Google translator

+ 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: 3
    Last Post: 01-01-2015, 06:26 AM
  2. How do I make the copy/paste of one column contingent on the copy/paste of another?
    By Kwasimitsu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2014, 01:51 PM
  3. Automate copy and paste and copy and paste back to excel
    By Bmw318be in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-23-2013, 05:42 AM
  4. Automate copy and paste and copy and paste back to excel
    By Bmw318be in forum Access Tables & Databases
    Replies: 0
    Last Post: 02-23-2013, 05:42 AM
  5. Replies: 1
    Last Post: 01-16-2013, 05:36 AM
  6. 2 Macro's: only vertical copy/paste action and copy-paste 14 columns to the right.
    By vdongen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2010, 10:34 AM
  7. Replies: 1
    Last Post: 01-04-2005, 06:06 PM

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