?
Solved

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

Posted on 2014-07-23
3
Medium Priority
?
632 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 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:Murray Brown
ID: 40215171
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

766 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