+ Reply to Thread
Results 1 to 3 of 3

Thread: Export worksheets from a workbook to the current workbook location path

  1. #1
    Registered User
    Join Date
    06-30-2010
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    13

    Exclamation Export worksheets from a workbook to the current workbook location path

    Hi All,



    I have a macro to export worksheets from the workbook to the specified path( The location path is to be set in the macros).



    Problem - when I moved the macro enabled workbook to another location, i usally want to change the location path in the vba editor manually. Is there a function to export the sheets to the path where the current workbook is placed?



    My macro looks like




    'Creates an individual workbook for each worksheet in the active workbook.
    Dim wbDest As Workbook
    Dim wbSource As Workbook
    Dim sht As Object 'Could be chart, worksheet, Excel 4.0 macro,etc.
    Dim strSavePath As String



    Application.ScreenUpdating = False 'Don't show any screen movement

    strSavePath = "C:\Documents and Settings\185568\Desktop\Transact Segregation - Final\" 'Change this to suit your needs -> I dont want this to be changed manually each time whenever i move this workbook

    Set wbSource = ActiveWorkbook

    For Each sht In wbSource.Sheets
    sht.Copy
    Set wbDest = ActiveWorkbook
    wbDest.SaveAs strSavePath & sht.Name
    wbDest.Close 'Remove this if you don't want each book closed after saving.
    Next

    ' deletes a sheet named strSheetName in the active workbook
    Application.DisplayAlerts = False
    Sheets("1").Delete
    Sheets("2").Delete
    Sheets("3").Delete
    Sheets("4").Delete
    Sheets("5").Delete
    Sheets("6").Delete
    Sheets("7").Delete
    Sheets("8").Delete
    Sheets("9").Delete
    Sheets("10").Delete
    Application.DisplayAlerts = True


    Application.ScreenUpdating = True
    MsgBox "Sheets are exported"

    End Sub


    "



    Can anyone help on this

  2. #2
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    mineral city, ohio
    MS-Off Ver
    Excel 2007; Excel 2000
    Posts
    4,004

    Re: Macros - Export worksheets from a workbook to the current workbook location path

    Hi legendkiller420

    A slap on the wrist will be coming your way if you don't wrap your code in code tags. Beside that, you won't get many responses until you do so.

    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Export worksheets from a workbook to the current workbook location path

    Your post does not comply with Rule 3 of our Forum RULES. 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 # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0