Need to save 1 sheet out of workbook and VBA or macro to import it.


Posted by Ron on June 14, 2001 9:26 AM

I want to add 2 buttons to a userform. One button will save 1 sheet only from the workbook to a new file and the other button will open a dialog box to select one of the saved worksheets and import it into the workbook. Ideas or suggestions??? Thanks.



Posted by tuc on June 14, 2001 11:35 AM

Ron,

Use the copy method of the worksheet object.
If you are copying within the same workbook, then the code would read "wsSheetToCopy.Copy Before:=wsSheetBefore" where wsSheetToCopy and wsSheetBefore are the worksheet objects. If you do not specify the Before (or After) it will be copied to a new workbook. You can also set wsSheetBefore to be a worksheet on a different workbook that the wsSheetBefore is located.

If you are going to use a dialog, then look at the GetOpenFileName method of the application object.
' Call the Open dialog and store the result in the string variable strHolder.
strHolder = Application.GetOpenFilename

Tuc