+ Reply to Thread
Results 1 to 11 of 11

Save AS file name as cell contents

  1. #1
    Registered User
    Join Date
    09-05-2008
    Location
    london
    Posts
    11

    Save AS file name as cell contents

    I know it must be on this forum somewhere but I've serached and can't find it. I would like to be able to open a template and save the contents of cell B19 as the file name.

    Can I do this so i don't have to press a button to run the macro. I have only done one macro previously and that was with the help of people on this forum so please don't get to technical.

    If possible I would like to be able to save it on the server X:\reports\offender PDF's

  2. #2
    Registered User
    Join Date
    09-05-2008
    Location
    london
    Posts
    11

    Re: Save AS file name as cell contents

    Apparently this is supposed to work

    Please Login or Register  to view this content.

    Unfortunately I get this error message

    Please Login or Register  to view this content.
    Last edited by Anonbrumbie; 10-07-2009 at 06:22 AM.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Save AS file name as cell contents

    The OzGrid website has started inexplicably adding an extra blank line between every line of text. That's usually not a problem until you get those multi-line pieces of code...which is broken completely by the extra lines. You have to take all of those lines out.
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    09-05-2008
    Location
    london
    Posts
    11

    Re: Save AS file name as cell contents

    Many thanks

    Do you know what I add to get it to run automatically
    Last edited by Anonbrumbie; 10-07-2009 at 11:14 AM.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Save AS file name as cell contents

    Please explain.

  6. #6
    Registered User
    Join Date
    09-05-2008
    Location
    london
    Posts
    11

    Re: Save AS file name as cell contents

    I want to be able to have the macro run without having to hit a short cut key or Alt F8. Ideally I would also like it to save straight to a folder on the server.

    I can only just get my head around basic formulas so macros might as well be another language

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Save AS file name as cell contents

    When exactly should this macro run itself? What in your mind would be the triggering moment that causes the sheet to selfsave/selfname?

  8. #8
    Registered User
    Join Date
    09-05-2008
    Location
    london
    Posts
    11

    Re: Save AS file name as cell contents

    I must be missing something here.

    What I want is to enter the data in the cell and then when I click on save as I want the macro to run. Currently I have to click on "run" or a short cut key to make it happen.

    Edit

    The penny has finally dropped. I didn't realise "run" incorprated save as. I thought it preceeded save as.
    Last edited by Anonbrumbie; 10-07-2009 at 01:36 PM.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Save AS file name as cell contents

    There is a workbook-event macro called Worbook_BeforeSave. If you create this event in the ThisWorkbook module, it intercepts the SAVE command and runs its code prior to a normal save. This macro will run its own code and then abort the normal save, so it always tries to save the sheet with the name in B19.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 10-07-2009 at 01:59 PM.

  10. #10
    Registered User
    Join Date
    09-05-2008
    Location
    london
    Posts
    11

    Re: Save AS file name as cell contents

    thanks for your help. It works. I just wish I knew how

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Save AS file name as cell contents

    Read through the macro line by line. Most VBA isn't that complicated to decipher when you know exactly what it is doing and just don't know how. As you read the code and find a line confuses you, Google that one term:

    Excel VBA MsgBox
    Excel VBA SaveAs


    ...and so some quick research on that term. Be sure to NOT Google terms that were declared as variables in the macro since they are user defined. (like strName in you macro).

    If you find you really can't decipher, ask again here about the specific line of code that remains a mystery.

    =============
    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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