Consulting

Results 1 to 13 of 13

Thread: Save Active Worksheet - Sever All Links

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Save Active Worksheet - Sever All Links

    Hi!
    I want to save the active worksheet (yes, in my case it'll only be one sheet, and its name is "estimate") to a new workbook. I want to have the save as dialog auto-fill with the contents of I9, a hyphen, and then the date in I12 in ddmmyyyy format.

    I need to sever all links and formulas, and save the values only.


    Do I need to upload a sample file?
    ~Anne Troy

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try this.

    Option Explicit
    
    Sub Macro1()
    Dim SaveAsName      As String
    SaveAsName = Range("I9").Text & " - " & Format(Range("I12").Value, "ddmmyyyy")
    Sheets("estimate").Copy
        With ActiveWorkbook.Sheets(1).UsedRange
            .Value = .Value
        End With
        Application.Dialogs(xlDialogSaveAs).Show SaveAsName
    End Sub

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Yep. Exactly like that, except my mistake, which I fixed. I wanted mmddyyyy. LOL!!

    Jake: You're the best. Do I say it often enough?

    By the way. If you're feeling lazy, you might want to ask that it be added to the KB. If you're feeling energetic, you might want to add it yourself.
    ~Anne Troy

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Glad to help

    Take Care

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    I knew it couldn't be so easy. Spoke to soon, Jake. Maybe it's not as hard as I think it'll be. How can I specify a path like MyDocuments\Estimates? (it currently goes to 1033, a system folder).

    I have some data validation dropdowns. I want to clear those, too, while keeping the values. The total range I care about is A1:G32, if it matters. And there's dropdowns in:

    A8:A21 and C4.

    I also have some conditional formatting in C4 and E4 that I'd wanna dump.

    Please?
    ~Anne Troy

  6. #6
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    How about this.

    Option Explicit
     
    Sub Macro1()
    Dim SaveAsName      As String
    'Specify default Save As name
        SaveAsName = Range("I9").Text & " - " & Format(Range("I12").Value, "ddmmyyyy")
    'Specify default Save As path
        ChDir "C:\"
    'Copy sheet to a new workbook
        Sheets("estimate").Copy
    'Replace formulas with values
        With ActiveWorkbook.Sheets(1).UsedRange
            .Value = .Value
        End With
    'Delete Validation and Conditional Formatting
        With ActiveWorkbook.Sheets(1).Cells
            .Validation.Delete
            .FormatConditions.Delete
        End With
    'Show the Save As Dialog
        Application.Dialogs(xlDialogSaveAs).Show SaveAsName
    End Sub

  7. #7
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Lookin good!!!!
    ~Anne Troy

  8. #8
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    If you will not know the path to the "MyDocuments" folder you can use this.


    ChDir CreateObject("WScript.Shell").SpecialFolders("MyDocuments")

  9. #9
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Actually, I've asked what specific folder, and haven't got a reply yet. This is fine. Thanks.
    ~Anne Troy

  10. #10
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Okay. One wast wittle pwobwem.

    The worksheet is protected.

    I was able to tweak the code to unprotect it (believe it??), but it's doing it on the original worksheet instead of the new worksheet.

    Ooops! I did it!!

    Sub NewEstimate()
    Dim SaveAsName      As String
    'Specify default Save As name
        SaveAsName = Range("I9").Text & " - " & Format(Range("I12").Value, "mmddyyyy")
    'Specify default Save As path
        ChDir "C:\"
    'Copy sheet to a new workbook
    Sheets("estimate").Copy
    'Replace formulas with values
        ActiveWorkbook.Sheets(1).Unprotect
    With ActiveWorkbook.Sheets(1).UsedRange
            .Value = .Value
        End With
    'Delete Validation and Conditional Formatting
        With ActiveWorkbook.Sheets(1).Cells
            .Validation.Delete
            .FormatConditions.Delete
        End With
    'Show the Save As Dialog
        Application.Dialogs(xlDialogSaveAs).Show SaveAsName
    End Sub
    Jake: You just might teach me this crap yet.
    ~Anne Troy

  11. #11
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I'm trying.

    Just a minor change so the comments make sense.


    Sub NewEstimate() 
    Dim SaveAsName      As String 
    'Specify default Save As name
        SaveAsName = Range("I9").Text & " - " & Format(Range("I12").Value, "mmddyyyy") 
    'Specify default Save As path
        ChDir "C:\" 
    'Copy sheet to a new workbook
        Sheets("estimate").Copy 
    'Remove sheet protection
        ActiveWorkbook.Sheets(1).Unprotect Password:=""
    'Replace formulas with values
        With ActiveWorkbook.Sheets(1).UsedRange 
            .Value = .Value 
        End With 
    'Delete Validation and Conditional Formatting
        With ActiveWorkbook.Sheets(1).Cells 
            .Validation.Delete 
            .FormatConditions.Delete 
        End With 
    'Show the Save As Dialog
        Application.Dialogs(xlDialogSaveAs).Show SaveAsName 
    End Sub

  12. #12
    VBAX Mentor Brandtrock's Avatar
    Joined
    Jun 2004
    Location
    Titonka, IA
    Posts
    399
    Location
    Quote Originally Posted by Dreamboat
    Jake: You just might teach me this crap yet.
    You gotta be careful Anne, this stuff is intoxicating. The more familiar you get with it, the more you want to know.

    Regards,
    Brandtrock




  13. #13
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Oh! I don't know if I'd go THAT far... ROFL!!
    ~Anne Troy

Posting Permissions

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