View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Copy Sheet into another workbook

Once you select the new workbook all code that is not otherwise referenced
will refer to the new book. So Sheets("Sheet4") is referenced to your new
workbook and not your original workbook. Two choicies

1.
Sheets("Sheet4").Select 'Not necessary

newFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),
*.xls", Title:="Please select a file")
If newFN = False Then
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=newFN
End If
ThisWorkbook.Select
Sheets("Sheet4").Move Befo=Workbooks("NewFN").Sheets(1)
2.
Sheets("Sheet4").Select 'Not necessary

newFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),
*.xls", Title:="Please select a file")
If newFN = False Then
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=newFN
End If
Windows(newFN).Select
Thisworkbook.Sheets("Sheet4").Move Befo=Workbooks("NewFN").Sheets(1)

--
HTH...

Jim Thomlinson


"Brennan" wrote:

Hello,

I am trying to automate the copying of a sheet into another workbook that I
have to select and I am not able to get my code to work. This is what I
have so far:

Sheets("Sheet4").Select

newFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),
*.xls", Title:="Please select a file")
If newFN = False Then
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=newFN
End If
Windows(newFN).Select
Sheets("Sheet4").Move Befo=Workbooks("NewFN").Sheets(1)

As you can see, I am selecting sheet 4. Then I open the workbook into which
I would like to copy sheet 4. I know how to automate moving a sheet into a
static workbook, but I want to be able to change the workbook as needed.
Thanks for your help.