Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-28-2017, 09:02 AM
AndreAndre AndreAndre is offline Excel VB Acceleration Windows 7 32bit Excel VB Acceleration Office 2007
Novice
Excel VB Acceleration
 
Join Date: May 2017
Posts: 1
AndreAndre is on a distinguished road
Default Excel VB Acceleration

I am trying to accelerate my Excel VB Macro significantly. I have tried the 5 alternatives below. I wonder if I could shorten the execution time further.


Sub AccelerateMacro()
'
' v1 052817 by eb+mb
' Macro to copy as fast as possible sheet from one workbook into another workbooks
' Declarations for variables are not shown to make code example more legible
' Macro is stored in and run from "DestinationWorkBook.xlsm"
StartTime = Timer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Alternative = "First"
If Alternative = "First" Then
Workbooks.Open Filename:="SourceWorkBook.xls"
Cells.Select
Selection.Copy
Windows("DestinationWorkBook.xlsm").Activate
Sheets("DestinationSheet").Select
Range("A1").Select
ActiveSheet.Paste
Windows("SourceWorkBook.xls").Activate
ActiveWorkbook.Close
End If
If Alternative = "Second" Then


Workbooks.Open Filename:="SourceWorkBook.xls", ReadOnly:=True
Cells.Select
Selection.Copy
Windows("DestinationWorkBook.xlsm").Activate
Sheets("DestinationSheet").Select
Range("A1").Select
ActiveSheet.Paste
Workbooks("SourceWorkBook.xls").Close SaveChanges:=False
End If
If Alternative = "Third" Then
' I could not get this alternative to work
Workbooks.Open("SourceWorkBook.xls").Worksheets("S ourceSheet").Copy
Workbooks.Open("DestinationWorkBook.xlsm").Workshe ets("DestinationSheet").Range("A1").PasteSpecial
End If
If Alternative = "Fourth" Then
' I could not get this alternative to work
Workbooks.Open("DestinationWorkBook.xlsm").Workshe ets("DestinationSheet").Range("A1") = Workbooks.Open("SourceWorkBook.xls").Worksheets("S ourceSheet")
End If
If Alternative = "Fifth" Then
' I don't understand the code in this alternative
Dim wbIn As Workbook
Dim wbOut As Workbook
Dim rSource As Range
Dim rDest As Range
Set wbOut = Application.Workbooks.Open("DestinationWorkBook.xl sm")
Set wbIn = Application.Workbooks.Open("SourceWorkBook.xls")
With wbIn.Sheets("SourceSheet").UsedRange
wbOut.Sheets("DestinationSheet").Range("A1").Resiz e(.Rows.Count, .Columns.Count) = .Value
End With

SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
End Sub
Reply With Quote
 

Tags
acceleration, excel vba acceleration



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word & Excel 2010 - Best Options To Auto Insert MySQL & Excel Data? Hoser Word 1 03-17-2017 03:47 PM
Embeding Excel Docs in Word - Receiving Memory Error Message if Excel is open kdash Word 0 05-06-2015 09:38 AM
Excel VB Acceleration How To Open an Macro From 2003 Excel in 2013 Excel Spread Sheet? ADubin Excel Programming 3 02-08-2015 04:57 AM
Excel VB Acceleration [Excel 2007] Building Power Point Slides from data in an Excel Table bremen22 Excel Programming 1 08-07-2013 11:01 AM
Excel VB Acceleration Excel 2011 can't open old Excel 98 or Excel X files FLJohnson Excel 8 05-09-2012 11:26 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:47 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft