+ Reply to Thread
Results 1 to 7 of 7

Macro to prevent switching ActiveBook

Hybrid View

  1. #1
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Macro to prevent switching ActiveBook

    Hi

    You can use ThisWorkbook, rather than ActiveWorkbook

    This is also a little bit neater, faster and avoids Activating altogether
    Sub copyData()
    
    Application.ScreenUpdating = False
       
    Workbooks.Add.Sheets("Sheet1").Range("A1:S25").Value = _
             ThisWorkbook.Sheets("Sheet1").Range("A1:S25").Value
    
    Application.ScreenUpdating = True
    End Sub
    Or maybe:
    Sub copyData()
    
    Application.ScreenUpdating = False
       
             ThisWorkbook.Sheets("Sheet1").Range("A1:S25").Copy _
                    Workbooks.Add.Sheets("Sheet1").Range("A1")
                    
    
    Application.ScreenUpdating = True
    End Sub
    If you want the formatting
    Last edited by Kyle123; 12-02-2011 at 10:50 AM.

+ 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