Choose, copy, add worksheet

femma

Board Regular
Joined
Jul 13, 2016
Messages
156
Hi!

I'm trying to copy a sheet to the end of another workbook, but my code does not do it. It opens the dialog box just fine but returns a object - error.

I also tried to tweek it so that it could not open the chosen workbook, but to no avail.

Thanks for your help!


Code:
Sub code()

Dim wb As Workbook
Dim my_FileName As Variant
Set wb = ThisWorkbook

my_FileName = Application.GetOpenFilename    '(FileFilter:=”Excel Files,*.xl*;*.xm*”)
If my_FileName <> False Then
Workbooks.Open Filename:=my_FileName
my_FileName.Copy After:=wb.Sheets(Sheet.Count)
my_FileName.Close SaveChanges:=False

End If

    
    my_FileName.Copy After:=wb.Sheets(Sheets.Count)


End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
"my_FileName" is name of workbook. You did not say sheet name.

The last opend workbook will be ActiveWorkbook.

ActiveWorkbook.Sheets("sheet1").copy After:=wb.Sheets(wb.Sheets.count)
ActiveWorkbook.Close SaveChanges:=False
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,602
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top