+ Reply to Thread
Results 1 to 9 of 9

Save a copy of workbook without comments

Hybrid View

fuerte Save a copy of workbook... 11-16-2018, 09:40 PM
Logit Re: Save a copy of workbook... 11-16-2018, 11:20 PM
fuerte Re: Save a copy of workbook... 11-26-2018, 01:59 PM
Arkadi Re: Save a copy of workbook... 11-26-2018, 02:05 PM
fuerte Re: Save a copy of workbook... 11-26-2018, 02:16 PM
Arkadi Re: Save a copy of workbook... 11-26-2018, 02:26 PM
fuerte Re: Save a copy of workbook... 11-26-2018, 02:44 PM
Arkadi Re: Save a copy of workbook... 11-26-2018, 02:45 PM
fuerte Re: Save a copy of workbook... 11-26-2018, 02:58 PM
  1. #1
    Registered User
    Join Date
    02-14-2018
    Location
    Wisconsin, USA
    MS-Off Ver
    2016
    Posts
    35

    Save a copy of workbook without comments

    I am trying to figure out how to save a copy of a workbook to a specified path without comments.

    That is to say... I need to save two copies of a workbook, one with comments and one without.

    I would like to be able to open the file that has comments and be able to execute a script that will remove comments, save a copy of the file to a specified path (overwriting the old file) and then have the comments restored to the original file.

    Has anyone ever tackled something like this before?

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Save a copy of workbook without comments

    .

    https://www.extendoffice.com/documen...mments.html#a1


    Delete All Comments In A Worksheet Or Workbook With VBA
    There is also VBA can help you to delete comments from a worksheet or a whole workbook.

    1. Press Alt + F11 to display the Microsoft Visual Basic for Applications window.

    2. In the window, click Insert > Module to show a new module window, then copy the following VBA code into the module window.

    VBA: Delete comments from a worksheet.

    Sub Remove_All_Comments_From_Worksheet()
    Cells.ClearComments
    End Sub


    VBA: Delete all comments from the whole workbook

    Sub DeleteAllComments()
    'Updateby20140613
    For Each xWs In Application.ActiveWorkbook.Sheets
    For Each xComment In xWs.Comments
    xComment.Delete
    Next
    Next
    End Sub

  3. #3
    Registered User
    Join Date
    02-14-2018
    Location
    Wisconsin, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Save a copy of workbook without comments

    I am aware of this script.

    I am trying to figure out how to:

    1. Strip comments
    2. Save a copy of the WB in another location without the comments.
    3. Undo the strip comments in original file.

    I need all three to be executed in the same script.

    Anyone got a suggestion?

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save a copy of workbook without comments

    Would it not be better to just SaveAs, remove comments and re-save. No undo needed that way, and the original workbook would retain its contents.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Registered User
    Join Date
    02-14-2018
    Location
    Wisconsin, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Save a copy of workbook without comments

    That would work as well. I tried just doing a clear comments button which ran a script similar to the one above and instructed the users how to do the save as manually..... Guess how long that took to get messed up? If you said hours.... Ding Ding! Your right!

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save a copy of workbook without comments

    Something like:

    Sub test()
    
    Dim fpath As String
    Dim fname As String
    Dim ws As Worksheet
    Dim myComment As Object
    
    fpath = "C:\temp\"
    fname = "myWorkbook.xlsm"
    Application.DisplayAlerts = False 'disable warning to overwrite
    ThisWorkbook.SaveAs fpath & fname
    Application.DisplayAlerts = True
    For Each ws In ThisWorkbook.Sheets
        For Each myComment In ws.Comments
            myComment.Delete
        Next myComment
    Next ws
    ThisWorkbook.Save
    
    End Sub

  7. #7
    Registered User
    Join Date
    02-14-2018
    Location
    Wisconsin, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Save a copy of workbook without comments

    Amazing. Works great! Is there a way to save the original document before executing the rest of the script?

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Save a copy of workbook without comments

    Oh yes forgot that.... just add
    ThisWorkbook.Save
    at the start of the code. Anywhere before we turn off display alerts.

  9. #9
    Registered User
    Join Date
    02-14-2018
    Location
    Wisconsin, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Save a copy of workbook without comments

    Works great! Thanks!

+ 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] Copy columns to new workbook with matched headers, then save new workbook as a text file.
    By haitran in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2017, 05:53 PM
  2. Copy comments and value from another sheet in the same workbook
    By acpt22 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-07-2013, 08:56 AM
  3. Copy and clear Comments from once woork book to other workbook
    By dhrumilp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-12-2013, 06:05 PM
  4. Replies: 5
    Last Post: 04-29-2005, 05:06 PM
  5. Help, I want to copy comments from close workbook
    By HuggyBear in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-10-2005, 06:32 PM
  6. Copy comments from closed workbook
    By HuggyBear in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 02-09-2005, 06:41 PM
  7. [SOLVED] Copy comments to several sheets in a workbook?
    By jen_l_333 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-07-2005, 08:06 PM

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