Consulting

Results 1 to 4 of 4

Thread: Impoting excel sheet to new workbook

  1. #1

    Impoting excel sheet to new workbook

    HI All,

    I have a excel workbook which contains 6-7 sheets. i want to write a vba code .. so that when i run, it should create a new work book on my desktop and import all the 7 sheets from the source Workbook.


    Regards
    Kumar

  2. #2
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    Just use the following with the workbook open (and put in your desktop path with the file-name)

    [vba]ActiveWorkbook.SaveCopyAs "c:\newworkbook.xls"[/vba]
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  3. #3
    Sub ImportTemplate()
    FileCopy "c:\Adventure.xlsm", _
    ActiveWorkbook.Path & "Adventureworks.xlsm"

    Name "C:\WorkedAdventist.xlsm" As "C:\Documents and Settings\All users\Desktop\Adventist.xlsm"
    End Sub

  4. #4
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    Please use the VBA tags to post code (it's easier to read).
    How you do it depends where you want to contain the code. If it's in a separate workbook it's OK but if it's in the file you want to copy you'll generate an error as it's already open. You might also get some unexpected results if there's more than one workbook open as the active one may not be the one you think. If you're referring to the workbook running code use "ThisWorkbook" instead.
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

Posting Permissions

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