Solved

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

Posted on 2014-07-23
3
622 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
[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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

742 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