Consulting

Results 1 to 4 of 4

Thread: Create different file

  1. #1

    Create different file

    I have an excel file with 2 sheets (one visible, Sheet1, and a hidden sheet, Sheet2) and I like using VBA code, to create 3 files on the desktop:
    - .PDF File to copy data from Sheet1 (range A1: G30)
    - .xlsx File to copy data from Sheet1 (range A1: G30), but delete button that acts VBA code
    - .xls file (in which there are no Sheet1 and in Sheet2, to delete columns A:K, also would like to remove VBA code)

    Can you help me?
    Thanks.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Sub vbax_52969_ExportRange_Pdf_xl51_xl56()
    
        Dim DTPath As String
        
        DTPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\"
        
        '1) pdf
        Sheets("Sheet1").Range("A1:G30").ExportAsFixedFormat Type:=xlTypePDF, Filename:=DTPath & "MyPDF.pdf"
        
        '2) xlsx
        Sheets("Sheet1").Range("A1:G30").Copy
        Workbooks.Add (xlWBATWorksheet)
        With ActiveWorkbook
            .Sheets(1).Cells(1).PasteSpecial
            .SaveAs DTPath & "MyXLSX.xlsx", 51
            .Close False
        End With
        
        '3) xls
        Sheets("Sheet1").UsedRange.Copy
        Workbooks.Add (xlWBATWorksheet)
        With ActiveWorkbook
            .Sheets(1).Cells(1).PasteSpecial
            .Sheets(1).Columns("A:K").Delete
            .SaveAs DTPath & "MyXLS.xls", 56
            .Close False
        End With
    
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Thank you very much mancubus.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome. i'm glad it helped.

    please mark the thread as "solved" from thread tools.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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