+ Reply to Thread
Results 1 to 3 of 3

Creating Flat Files and Export

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-23-2013
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 365
    Posts
    166

    Creating Flat Files and Export

    I am using the following code to flatten sheets in my file to export them without the formulas, how can I specify which sheets to flatten and export? I don't need them all to be exported.

    Sub CreateWorkbooks()
    Dim wbDest As Workbook
    Dim wbSource As Workbook
    Dim sht As Object
    Dim strSavePath As String
    Dim r As Long, c As Long, ws As Worksheet
    On Error GoTo ErrorHandler
    
    Application.ScreenUpdating = False
    
    
    strSavePath = "S:\savelocation\"
    
    
    Set wbSource = ActiveWorkbook
    
    
    For Each sht In wbSource.Sheets
    r = sht.Rows.Find("*", , , , xlByRows, xlPrevious).Row
    c = sht.Columns.Find("*", , , , xlByColumns, xlPrevious).Column
    sht.Copy
    Set ws = ActiveSheet
    ws.Range("A1").Resize(r, c).Value = sht.Range("A1").Resize(r, c).Value
    Set wbDest = ActiveWorkbook
    wbDest.SaveAs strSavePath & sht.Name
    wbDest.Close
    Next
    
    Application.ScreenUpdating = True
    
    ErrorHandler:
    
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    45,281

    Re: Creating Flat Files and Export

    For example:

    Option Explicit
    
    Sub sListSheets()
    
    Dim vArray, vElement
    vArray = Array("Sheet1", "Sheet3")
    For Each vElement In vArray
        Debug.Print Sheets(vElement).Name
    Next
    
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    08-23-2013
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 365
    Posts
    166

    Re: Creating Flat Files and Export

    Thanks TM, I inputted which sheets to export and ran but nothing happened. Also, where do I put the destination for which to save the flat files?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Sheet Export Macro to Flat File
    By JPSIMMON in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-18-2015, 05:57 PM
  2. Replies: 1
    Last Post: 02-10-2014, 09:13 PM
  3. [SOLVED] VB to extract comments to new sheet, creating CSV flat file
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2014, 07:44 PM
  4. Creating a Pyramid Hierarchy structure from a flat structure
    By thegamerulez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2014, 01:28 AM
  5. Replies: 0
    Last Post: 03-15-2012, 04:13 PM
  6. Archiving Files - Creating New Folders and Moving Files
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2011, 06:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1