Solved

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

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

Industry Leaders: 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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

728 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