+ Reply to Thread
Results 1 to 7 of 7

Sheet Export Macro to Flat File

Hybrid View

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

    Sheet Export Macro to Flat File

    I use this code to export my worksheets to a folder as separate flat files, so none of the formulas or references carry over, just the values.
    It doesn't seem to work, it is only exporting the first worksheet.

    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:\yyyyyyy\vvvvv\xxx\"
    
    
    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 xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sheet Export Macro to Flat File

    Maybe:

    Sub CreateWorkbooks() 'JP Simmon
    Dim wbDest As Workbook, wbSource As Workbook: Set wbSource = ActiveWorkbook
    Dim sht As Worksheet, ws As Worksheet
    Dim strSavePath As String, r As Long, c As Long: strSavePath = "S:\yyyyyyy\vvvvv\xxx\"
    
    On Error GoTo ErrorHandler
    
    Application.ScreenUpdating = False
    For Each sht In wbSource.Sheets
    r = sht.Rows.Find("*", , , , xlByRows, xlPrevious).Row
    c = sht.Columns.Find("*", , , , xlByColumns, xlPrevious).column
    Workbooks.Add
    Set wbDest = ActiveWorkbook: Set ws = ActiveSheet
    ws.Range("A1").Resize(r, c).value = sht.Range("A1").Resize(r, c).value
    wbDest.SaveAs strSavePath & sht.Name
    wbDest.Close False
    Next
    ErrorHandler:
    Application.ScreenUpdating = True
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

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

    Re: Sheet Export Macro to Flat File

    Thank you for the help,

    Still not exporting tabs into folder though

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sheet Export Macro to Flat File

    Well then maybe:

    Sub CreateWorkbooks() 'JP Simmon
    Dim wbDest As Workbook, wbSource As Workbook: Set wbSource = ActiveWorkbook
    Dim sht As Worksheet, ws As Worksheet
    Dim strSavePath As String, r As Long, c As Long: strSavePath = "S:\yyyyyyy\vvvvv\xxx\"
    
    On Error GoTo ErrorHandler
    
    Application.ScreenUpdating = False
    For Each sht In wbSource.Sheets
    sht.copy
    Set wbDest = ActiveWorkbook
    wbDest.SaveAs strSavePath & sht.Name
    wbDest.Close False
    Next
    ErrorHandler:
    Application.ScreenUpdating = True
    End Sub

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

    Re: Sheet Export Macro to Flat File

    Thanks dept. It is exporting the separate files with the formulas, anyway I can flatten them to just have values?
    Last edited by JPSIMMON; 08-18-2015 at 03:31 PM.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sheet Export Macro to Flat File

    Hi JP,

    Thanks for the rep!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sheet Export Macro to Flat File

    Hopefully,

    Sub CreateWorkbooks() 'JP Simmon
    Dim wbDest As Workbook, wbSource As Workbook: Set wbSource = ActiveWorkbook
    Dim sht As Worksheet, ws As Worksheet
    Dim strSavePath As String, r As Long, c As Long: strSavePath = "S:\yyyyyyy\vvvvv\xxx\"
    
    On Error GoTo ErrorHandler
    
    Application.ScreenUpdating = False
    For Each sht In wbSource.Sheets
    sht.copy
    
    Set wbDest = ActiveWorkbook: Set ws = ActiveSheet
    ws.Cells.copy
    ws.Range("A1").PasteSpecial xlPasteValues
    
    wbDest.SaveAs strSavePath & sht.Name
    wbDest.Close False
    Next
    ErrorHandler:
    Application.ScreenUpdating = True
    End Sub

+ 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] 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
  2. [SOLVED] Excel macro to create a flat file?
    By jlang11 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-18-2013, 03:05 PM
  3. Create Flat File from Macro
    By jackfsm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2009, 02:15 PM
  4. Macro to copy a column data to flat file or text file
    By vinaynagasani in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-01-2009, 10:56 AM
  5. How to embed a macro in a flat file?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-19-2006, 08:05 AM
  6. [Macro excel] How to create and export a sheet into a *.inp (or *.txt) file
    By MrKermit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2006, 03:30 AM
  7. Save sheet as fixed length (flat) text file
    By Tim Donovan in forum Excel General
    Replies: 0
    Last Post: 05-24-2005, 03:08 PM
  8. PDF to Excel as flat file, via macro
    By CLR in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-18-2005, 10:06 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