Solved

Excel VBA Copy the contents/formatting of a range to a closed workbook

Posted on 2014-07-23
3
604 Views
Last Modified: 2014-07-23
Hi

What Excel VBA code would I use to copy the an Excel range to another closed Excel spreadsheet
0
Comment
Question by:murbro
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 40214052
This will take the current selection, create a new workbook, and add the selection to Sheet1 Cell A1 of the new workbook and save it as copyRange.xlsm
Sub CopyRange()
    Dim xls As Excel.Worksheet
    Dim rng As Excel.Range
    Dim xlb As Excel.Workbook
    Set rng = Excel.Selection
    Set xlb = Workbooks.Add()
    xlb.Application.DisplayAlerts = False
    
    Set xls = xlb.Sheets("Sheet1")
    rng.Copy Destination:=xls.Range("A1")
    xlb.SaveAs "copyRange.xlsm", xlOpenXMLWorkbookMacroEnabled, AccessMode:=xlExclusive, ConflictResolution:=Excel.XlSaveConflictResolution.xlLocalSessionChanges
    xlb.Close False
End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 40215171
Thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now