+ Reply to Thread
Results 1 to 19 of 19

How do I save a WorkBook using only select cells macro

Hybrid View

  1. #1
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    How do I save a WorkBook using only select cells macro

    Hey,

    I need to save a Workbook using only selected sheets....

    I have this at the moment which is working, but it is saving the whole workbook, and I need it to work with only the range "A1:K40"

    Sub SaveInvWithNewName()
        Dim NewInv As Variant
        ActiveSheet.Copy
        NewInv = "C:\Invoices\LeeValley-Inv" & Range("F2").Value & ".xlsx"
        ActiveWorkbook.SaveAs NewInv
        ActiveWorkbook.Close
        MsgBox "File Saved to C:\Invoices"
        NextInvoice
    End Sub


    I tried this but didnt work - any ideas?

    Sub SaveInvWithNewName()
        Dim NewInv As Variant
        ActiveSheet.Copy
        NewInv = "C:\Invoices\LeeValley-Inv" & Range("F2").Value & ".xlsx"
        ActiveWorkbook.Range("A1:K40").SaveAs NewInv
        ActiveWorkbook.Close
        MsgBox "File Saved to C:\Invoices"
        NextInvoice
    End Sub
    Last edited by jeremiasapaz; 04-27-2017 at 05:10 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    Hi jeremiasapaz

    Welcome to the forum
    In future please view the forum rules before posting. Your post does not comply with rule #3.
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window.

    Are you wanting to have only Range("A1:K40").copied to a new workbook and save that workbook?
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    Give this a try...
    Option Explicit
    
    Sub SaveInvWithNewName()
        Dim NewInv As Variant
        Dim NewBook As Workbook
        NewInv = "C:\Invoices\LeeValley-Inv" & "-" & ActiveSheet.Range("F2").Value & ".xlsx"
        ActiveSheet.Range("A1:K40").Copy
        Set NewBook = Workbooks.Add
        NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial (xlPasteValues)
        NewBook.SaveAs Filename:=NewInv
        MsgBox "File Saved to C:\Invoices"
    End Sub
    Last edited by Sintek; 04-27-2017 at 04:50 AM.

  4. #4
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    Quote Originally Posted by sintek View Post
    Give this a try...
    Option Explicit
    
    Sub SaveInvWithNewName()
        Dim NewInv As Variant
        Dim NewBook As Workbook
        NewInv = "C:\Invoices\LeeValley-Inv" & "-" & ActiveSheet.Range("F2").Value & ".xlsx"
        ActiveSheet.Range("A1:K40").Copy
        Set NewBook = Workbooks.Add
        NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial (xlPasteValues)
        NewBook.SaveAs Filename:=NewInv
        MsgBox "File Saved to C:\Invoices"
    End Sub


    I am receiving an error on this line

    NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial (xlPasteValues)

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    Originally Posted by Pete_UK
    To attach a file, click on Go Advanced (below the Edit Window) while you are composing a reply, then scroll down to and click on Manage Attachments and the Upload window will open. Click on Browse and navigate to (and double-click) the file icon that you want to attach, then click on Upload and then on Close this Window to return to the Edit window. When you have finished composing your post, click on Submit Post.

  6. #6
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    SpreadsheetProject-JeremiasPaz-R00132786.xlsm

    I was trying that but it is jerky for me... I think it worked now...

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    What information in is your copy range...Any chance you can upload a sample workbook. Worked fine when testing on my workbook.

  8. #8
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    The attach option is not working - tried from my mobile and didnt work either

    I added to a temp FTP - not sure if you have access to that

    sftp vfdZ61LGD@ftp.emc.com
    Password: Bj8A5AB558

    Connecting via a web browser:


    https://ftp.emc.com/action/login?dom...ord=Bj8A5AB558

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    Rather go this route as it is a invoice template...
    Option Explicit
    
    Sub SaveInvWithNewName()
        Dim NewInv As Variant
        Dim NewBook As Workbook
        NewInv = "C:\Invoices\LeeValley-Inv" & "-" & ActiveSheet.Range("F2").Value & ".xlsx"
        ThisWorkbook.ActiveSheet.Copy
        ActiveSheet.Pictures.Delete
        ActiveWorkbook.SaveAs NewInv
        MsgBox "File Saved to C:\Invoices"
    End Sub
    Last edited by Sintek; 04-28-2017 at 01:55 AM. Reason: Added Picture delete line of code

  10. #10
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    Quote Originally Posted by sintek View Post
    Rather go this route as it is a invoice template...
    Option Explicit
    
    Sub SaveInvWithNewName()
        Dim NewInv As Variant
        Dim NewBook As Workbook
        NewInv = "C:\Invoices\LeeValley-Inv" & "-" & ActiveSheet.Range("F2").Value & ".xlsx"
        ThisWorkbook.ActiveSheet.Copy
        ActiveWorkbook.SaveAs NewInv
        MsgBox "File Saved to C:\Invoices"
    End Sub


    But that will not save the selection I want, it will save everything...

    Also I am getting an error in "ActiveWorkbook.SaveAs NewInv"

  11. #11
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    I will upload one in a min... just need to add some dummy data instead and change some info on it...
    Give me 5 min...

  12. #12
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    Nope...It only saves the Invoice...This is the result I get after running code
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    Quote Originally Posted by sintek View Post
    Nope...It only saves the Invoice...This is the result I get after running code
    Tnx but I will need a version that save only that range..

    tnx anyway

  14. #14
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    Jeremia

    Please explain what you are wanting to save cause the ActiveSheet.Range("A1:K40") is in fact the invoice not so....

    EDIT:
    Option Explicit
    
    Sub SaveInvWithNewName()
        Dim NewInv As Variant
        Dim NewBook As Workbook
        NewInv = "C:\Invoices\LeeValley-Inv" & "-" & ActiveSheet.Range("F2").Value & ".xlsx"
        ActiveSheet.Range("A1:K40").Copy
        Set NewBook = Workbooks.Add
        NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        NewBook.SaveAs Filename:=NewInv
        MsgBox "File Saved to C:\Invoices"
    End Sub
    Last edited by Sintek; 04-27-2017 at 07:29 AM.

  15. #15
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    Quote Originally Posted by sintek View Post
    Jeremia

    Please explain what you are wanting to save cause the ActiveSheet.Range("A1:K40") is in fact the invoice not so....

    EDIT:
    Option Explicit
    
    Sub SaveInvWithNewName()
        Dim NewInv As Variant
        Dim NewBook As Workbook
        NewInv = "C:\Invoices\LeeValley-Inv" & "-" & ActiveSheet.Range("F2").Value & ".xlsx"
        ActiveSheet.Range("A1:K40").Copy
        Set NewBook = Workbooks.Add
        NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        NewBook.SaveAs Filename:=NewInv
        MsgBox "File Saved to C:\Invoices"
    End Sub


    Hi - The reason why I want only that Range is to remove the 3 buttons I have there so the invoice will only have the data not the Macro Buttons...

  16. #16
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    May I suggest deleting pictures before saving....i.e then the code in post 10 which I amended by adding below line will work.
    ActiveSheet.Pictures.Delete

  17. #17
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    Quote Originally Posted by sintek View Post
    May I suggest deleting pictures before saving....i.e then the code in post 10 which I amended by adding below line will work.
    ActiveSheet.Pictures.Delete
    you are the man - spot on....





    do you mind if I ask another question?

    I am trying to use the macro below to just paste a formula back in a cell - but it is not accepting the YES in the formula

    do you know how I can do that?

        Range("B12:C12").Formula = "=IF(B6="","",IF($C$11="Yes",B6,"Type Customer Name Manually"))"
        Range("B13:C13").Formula = "=IF(B7="","",IF($C$11="Yes",B7,"Type Address Manually"))"
        Range("B15:C15").Formula = "=IF(B9="","",IF($C$11="Yes",B9,"Type County Manually"))"
        Range("B16:C16").Formula = "=IF(B10="","",IF($C$11="Yes",B10,"Type Country Manually"))"

  18. #18
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: How do I save a WorkBook using only select cells macro

    Not ideal to post question about something else in this post, but try this....
    ""Yes""
    Please amrk this thread as solved . Thanks for rep point.

  19. #19
    Registered User
    Join Date
    04-21-2017
    Location
    IReland
    MS-Off Ver
    2010
    Posts
    10

    Re: How do I save a WorkBook using only select cells macro

    Quote Originally Posted by sintek View Post
    Not ideal to post question about something else in this post, but try this....
    ""Yes""
    Please amrk this thread as solved . Thanks for rep point.
    Again thank you so much, that fixed the issue, I will mark as solved now

+ 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] VBA / Macro to Select File and Save As
    By bloomingcarrot in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2015, 01:13 AM
  2. [SOLVED] Macro to save workbook - Create Directories / Sub-Directories Based using text in cells
    By kspeese in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2014, 01:21 PM
  3. [SOLVED] Save the split the workbook file type as Excel Binary Workbook From Run Macro
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-25-2013, 05:09 AM
  4. Macro to open a closed workbook and select copy cells into an open workbook
    By helloganesh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2013, 02:00 PM
  5. [SOLVED] Macro to pull out data from specific cells and save it in another workbook
    By kittu55 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-02-2013, 11:02 AM
  6. Macro to select cells and save as html
    By itmanusa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-27-2010, 09:20 AM
  7. [SOLVED] Select sheet tabs in workbook & save to separate workbook files
    By stratocaster in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-01-2006, 11:40 AM

Tags for this Thread

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