Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying Worksheets in Excel via Access?

Status
Not open for further replies.

DaddyNackers

Programmer
Oct 4, 2002
16
US
I am trying to copy a worksheet in an excel workbook and paste it within the same workbook using VBA.

For example, I want to copy "Sheet 1" before "Sheet 8" using VBA code. Does anyone know how to do this? I am using MS Access 97.

The following code is where I am at right now (it doesn't work though)???

wBook.Worksheets("CC5_Graph").Copy (Sheets(i + 5))

This code gives me the following error:
"Method 'Sheets' of object '_Global' failed" err.num = '1004'

I appreciate any and all help!
Thanks,
Nackers
 
Try:

wBook.Worksheets("CC5_Graph").Copy after:=wBook.sheets(i+5)

Rob
[flowerface]
 
When I do this:

wBook.Worksheets("CC5_Graph").Copy before:=wBook.sheets(6)

it gives me the following error:
"Subscript out of range" err.num = "9"

The funny thing is that wBook.Sheets.Count = 10.

I tried the following code also and got the same error:

wBook.Worksheets("CC5_Graph").Copy before:=wBook.Worksheets("CC1_Data")

Any suggestions????

Thanks,
Nackers
 
It looks as if the sheet you're trying to copy is a chart sheet. In that case, it will not appear in the worksheets collection. Try

wBook.sheets("CC5_Graph").Copy before:=wBook.sheets(6)

instead.

Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top