+ Reply to Thread
Results 1 to 2 of 2

Copy and Paste not working during BeforeSave

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-14-2006
    Location
    USA
    MS-Off Ver
    2019
    Posts
    686

    Copy and Paste not working during BeforeSave

    The Live worksheet contains formulas linked to other workbooks so in an effort to retain a static copy of the calculations at the time of saving I'm copying and pasting the Live sheet values to the Static sheet.

    If I run this manually it runs fine.
    If I call it from the BeforeSave or embed it into BeforeSave it steps through the lines of code but does nothing.

    When BeforeSave initiates the activesheet is always Live.

    Sub SaveStatic()
    
    ‘just in case their currently false due to other code
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    
    'clear the Static Sheet
        Static.Cells.Clear
    
    'Copy & Paste Live VALUES  to Static
        Live.Range("A1:R79").Copy
        Static.Activate
        Static.Range("A1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
    
    Live.Activate
    
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    
    End Sub

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Copy and Paste not working during BeforeSave

    I noticed that you used codenames for the worksheet objects (Static and Live). As far as I'm aware, you shouldn't be able to use the code name "Static" as a codename for a worksheet.

    I ran your code, with a small adjustment for the use "Static" to refer to the worksheet name instead and it seems to be working on my end. Not too sure what's going on on your version. Are you able to send the original Excel file (with any important data removed of course) for us to play with?

    The code I used for my testing as below:
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Call SaveStatic
    End Sub Sub SaveStatic() 'just in case their currently false due to other code Application.EnableEvents = True Application.ScreenUpdating = True 'clear the Static Sheet Worksheets("Static").Cells.Clear 'Copy & Paste Live VALUES to Static Live.Range("A1:R79").Copy Worksheets("Static").Activate Worksheets("Static").Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Live.Activate Application.EnableEvents = True Application.ScreenUpdating = True End Sub
    Last edited by quekbc; 06-23-2015 at 08:05 PM. Reason: Formatting

+ 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. BeforeSave Macro Not Working
    By DMumme in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-14-2014, 01:00 PM
  2. Replies: 2
    Last Post: 08-17-2012, 08:16 AM
  3. Replies: 1
    Last Post: 03-08-2012, 03:03 AM
  4. BeforeSave not working properly
    By kingdt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-09-2007, 10:43 AM
  5. Replies: 9
    Last Post: 07-05-2005, 08:05 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