PDA

View Full Version : Impoting excel sheet to new workbook



kumark
07-30-2012, 12:42 AM
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

Teeroy
07-30-2012, 04:06 AM
Just use the following with the workbook open (and put in your desktop path with the file-name)

ActiveWorkbook.SaveCopyAs "c:\newworkbook.xls"

kumark
07-30-2012, 09:26 PM
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

Teeroy
07-30-2012, 11:36 PM
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.