+ 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,

    Here you are

    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("A:K").Copy
    Application.DisplayAlerts = False
    Set newWb = Workbooks.Add
        With newWb
            .Sheets(1).Range("A1").PasteSpecial xlPasteAll
            .Sheets(1).UsedRange.RowHeight = 12.75
            With.Sheets(1).PageSetup
                 .PrintArea = oldWb.Sheets(3).PageSetup.PrintArea
                 .Orientation = xlLandscape
                 .PrintGridlines = True
             End with
            .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
    Another time it would be best if you described your full question/outcome in your first post as this way off adding questions along the way makes for alot of rewriting.

    Steffen Thomsen
    Last edited by Steffen Thomsen; 11-16-2011 at 03:28 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,

    Sincere appologies if you feel I've mislead you, that certainly wasn't the intention.

    I'd tried to make myself as clear as possible and I hoped that "save the sheet “Data Sheet” as a new xlsx file with values and formatting" would be enough but I can see now that I should have been more specific. As you know it was an Example workbook that I posted as I couldn't post the actual one that I'm working on. Unfortunately I forgot to format the Data Sheet the same as the original in respect to the sheet middle header and print setup which didn't help.

    I've tried the new code and it works, but still loses the sheet header and print settings. I've posted a new file ExampleData_05.xlsm which has the correct formatting for the Data Sheet and includes your code.

    Regards

    Keith
    Attached Files Attached Files

+ 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