+ Reply to Thread
Results 1 to 7 of 7

Macro to save selected worksheets as workbooks in variable location

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Macro to save selected worksheets as workbooks in variable location

    Hi everyone,

    I have the following code:

    Please Login or Register  to view this content.
    Right now the code will save each worksheets in the workbook as a separate PDF in the predefine location. What I would to do is:

    1. Have the macro only save the active worksheet(s) in the workbook (i.e., the ones I've selected and are highlighted in white in the workbook)
    2. Have file explorer open so I can select where I want the PDFs to be saved.

    Any ideas?

    Thanks everyone!!!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro to save selected worksheets as workbooks in variable location

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 08-24-2015 at 03:59 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to save selected worksheets as workbooks in variable location

    Hi AlphaFrog,

    Thanks very much for the code. It nearly works perfectly, except for an interesting bit:

    If is select 4 worksheets in the workbook, the code will correctly create 4 PDFs and using the worksheet name and put it in the folder I select.

    However,

    When I check each PDF, each PDF actually has all four worksheets published in them. So for example, say I have worksheets 1, 2, 3, and 4. The code will publish 4 worksheets called 1, 2, 3, 4, but within each PDF has all four worksheets. What I was going for is to have each worksheet selected PDF'ed with only the contents of that particular worksheet.

    Any ideas?

    Thanks!!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro to save selected worksheets as workbooks in variable location

    Try this...

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to save selected worksheets as workbooks in variable location

    Hi AlphFrog,

    It works perfectly. Thanks very much. I understand your code except for the wsArr. Could you explain to me what that does? I'm not sure I understand the difference between:

    Dim ws as worksheet
    and
    Dim wsArr as Sheets.

    Thanks!!!

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro to save selected worksheets as workbooks in variable location

    You're welcome.

    The variable wsArr is used to store the collection of selected sheets because later each sheet is selected one-at-a-time so the ws.ExportAsFixedFormat saves the one selected sheet. Then after all the sheets are exported, wsArr is used to reselect all the original selected sheets.

    It's not really needed except to restore the original selected sheets. You could remove the three lines of code that include wsArr and it would still work except only one sheet is selected in the end.

  7. #7
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to save selected worksheets as workbooks in variable location

    I see. that's great. Thanks very much for your help.

+ 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. Macro to cut and paste a variable number of rows to a variable location?
    By TheClaw2323 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-03-2015, 07:57 AM
  2. Macro to insert a variable number of rows into a variable location
    By TheClaw2323 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-08-2015, 05:31 AM
  3. Macro to Auto save a backup copy in a seperate location OR save file with a pop up
    By kdsanderson30 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-12-2014, 12:38 PM
  4. Copy selected worksheets between workbooks onto named worksheets
    By AndrewSimpson87 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-24-2014, 03:25 PM
  5. Replies: 9
    Last Post: 06-24-2013, 04:14 PM
  6. [SOLVED] [Help]macro to open file browser, to select a location, and save the location to a cell
    By zhuleijia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 09:56 AM
  7. Cope worksheets and save to location
    By ozcank in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2005, 11:14 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