+ Reply to Thread
Results 1 to 16 of 16

Can VBA Export a Sheet to a Non-Macro Enabled File?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Can VBA Export a Sheet to a Non-Macro Enabled File?

    I did some research on this, and I thought for sure that this would work, but it still saves as a macro-enabled file...

    Sub ExportData()
    
        Dim FileDate As String
        Dim FileName As String
        Dim ReportDate as Date
        Dim FilePath as String
        Dim FinalBook as String
            
        Application.DisplayAlerts = False
        ThisWorkbook.CheckCompatibility = False
    
        ReportDate = (Date - 1)
        FilePath = ThisWorkbook.Path & "\"
        FinalBook = "Report - "
        
        'Set up file name
        FileDate = Format(ReportDate, "mm-dd-yy")
        FileName = FilePath & FinalBook & FileDate
        
        'Select only the sheet with the final data and save as separate non-macro-enabled file
        ThisWorkbook.Worksheets(1).Copy
        ActiveWorkbook.SaveAs FileName:=FileName, FileFormat:=xlOpenXMLWorkbook
        ActiveWorkbook.Close
            
        Application.DisplayAlerts = True
    
    End Sub 'ExportData
    The only thing I've done is to put a "1" in place of a string which is set as a constant at the beginning of my entire project, and I've moved a few of the variables and their declarations into this subroutine (so, changed from "Global" to "Dim").

    I'm working in Excel 2016, but this file may also be used by others working with Excel 2010, so it needs to work for both.

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    Hi,

    Try changing:
    FileName = FilePath & FinalBook & FileDate
    to:
    FileName = FilePath & FinalBook & FileDate & ".xlsx"
    Regards,
    Stephen

    If you feel someone has helped you please thank them and click on the star on their post to add reputation.
    Please ensure that you use code tags where relevant, and mark solved threads as solved.
    Most of all please be respectful and understanding of others.

  3. #3
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    spitfireblue,

    I was hopeful... but nope, still saves with the macros in place.

  4. #4
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    Drat, seems like there really isn't a way to do this.

  5. #5
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    Can you upload the file, because it was working for me.

  6. #6
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    In fact, try running the macro in this workbook.

    Example.xlsm

  7. #7
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    OK, it took me a while to clear out all the confidential data. I hope I've left enough information for you to test with. Let me know if you need more/different info.
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    I ran it and this is what came out.
    All the macros have been removed!
    Report - 05-18-16.xlsx

  9. #9
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    OK, this makes NO sense to me whatsoever. I did not change the Export subroutine at all in that file, but when I open my original file and use the button to run that subroutine, the macros are still in the file.

  10. #10
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    It makes no sense to me either!?! Are you sure you are looking at the right file?
    Run this one Report Automated Draft.xlsm and then post the result file that you will find in C:/Temp/

  11. #11
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    When I open the file I get from running my version, I get a message "SECURITY WARNING Automatic update of links has been disabled" with an "Enable Content" button. The link, when checked, is to my version of the report which created it. Breaking the link seems to fix the issue, but I don't want the end user to have to do that.

    When I save your version to the local Downloads folder and press the button, I get a Run-time error that Excel cannot access the file 'C:\Temp\11AAA111' (numbers replaced by 1, letters replaced by A). I will try on another computer that is not on the company network just for testing purposes, but won't be able to do that until tomorrow.
    Last edited by dhunton; 05-21-2016 at 05:38 PM.

  12. #12
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    Works fine on another computer. Differences between them: test computer has Excel 2010 and is NOT on the company network; final computer has Excel 2013 and IS on the company network.

    I have tried running it in a directory on the computer as well as one on the network, and it makes no difference.

    Any other ideas?

  13. #13
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    The export shows as a .xlsx file. I have buttons the end user will use to activate the VBA programming. When one of those is pressed in the exported file, it opens the file that was used to export it (i.e. the original .xlsm file).

    Is there any way to avoid this?

  14. #14
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    Remove the buttons..... if they are shapes you can do that like this:

    Sub DelShp()
    Dim sh As Shape
    For Each sh In ActiveSheet.Shapes
        sh.Delete
    Next sh
    End Sub

  15. #15
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    Or
    Application.CopyObjectsWithCells = False
    Sheets(1).Copy
    Application.CopyObjectsWithCells = True

  16. #16
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Can VBA Export a Sheet to a Non-Macro Enabled File?

    Used bakerman2's suggested solution - worked perfectly to cut the link between the non-VBA worksheet and the one that created it!

    YOU GUYS ROCK!

+ 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. [SOLVED] Save file as macro-enabled with path and file name from a cell
    By BRISBANEBOB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2015, 11:51 PM
  3. Macro Enabled File
    By caracadon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2014, 03:14 PM
  4. Macro that will export a sheet to a .dat text file (Excel 2003)
    By CameronR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2013, 08:47 AM
  5. [SOLVED] Export hidden sheet to .csv file with dynamic name and date via macro.
    By f1torque in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-26-2012, 07:57 AM
  6. Replies: 2
    Last Post: 07-18-2012, 11:17 PM
  7. [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

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