+ Reply to Thread
Results 1 to 12 of 12

Macros To Save Worksheet as New xlsx file & Save Another Worksheet As A Text File

Hybrid View

  1. #1
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Macros To Save Worksheet as New xlsx file & Save Another Worksheet As A Text File

    Hi,

    It needed a bit of alteration as you can se, this should work though

    Sub Steffen()
    
    Dim newWb As Workbook
    Dim oldWb As Workbook
    
    Set oldWb = ThisWorkbook
    
    Open "C:\\Users\Path\" & Sheets(4).Range("C6").Value & ".txt" For Append As #1
        For i = 1 To Sheets(3).UsedRange.Rows.Count
            Print #1, Sheets(3).Cells(i, 1).Value
        Next i
    Close #1
    
    Sheets(2).Range("A1:K" & Sheets(3).UsedRange.Rows.Count).Copy
    Application.DisplayAlerts = False
    Set newWb = Workbooks.Add
        With newWb
            .Sheets(1).Range("A1").PasteSpecial xlPasteAll
            .SaveAs "C:\Users\Path\" & oldWb.Sheets(4).Range("C8").Value & ".xlsx", FileFormat:=51
            .Close
        End With
    On Error GoTo err
    
    err:
    Application.DisplayAlerts = True
    
    End Sub
    Last edited by Steffen Thomsen; 11-16-2011 at 02:55 PM.
    Please take time to read the forum rules

  2. #2
    Registered User
    Join Date
    11-05-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Macros To Save Worksheet as New xlsx file & Save Another Worksheet As A Text File

    Steffen,

    That works really well, but is it possible to save the new xlsx file to have the same settings as the original sheet. ie. Column widths, Sheet Header & Print settings (Landscape, fit to one sheet, print gridlines)?

    Thanks

    Keith

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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