Information générale
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Try this
first assign the work sheet that you want to place the copy after. in this case sheet 2
objsheet = obj.Application.Workbooks(1).Worksheets('Sheet2')
this copys that first work sheet and palces it after sheet 2
obj.Application.Workbooks(1).Worksheets('Sheet1').copy(objsheet)
this is the test code I used for the references used above.
obj = createobject('excel.application')
obj.application.workbooks.open('E:\Proginfo\solutions\com\test.xls')
>Hello:
>
>I have recorded a macro in Excel to copy a worksheet and came up with the following code:
>
>Sheets("master").Select
>Sheets("master").Copy After:=Sheets(2)
>Sheets("master (2)").Select
>Sheets("master (2)").Name="38730"
>
>I added this to something I had that worked...
>oleApp=createobject("Excel.Application")
>oleApp.Workbooks.open("filename.xls")
>
>...then added the code above as...
>oleApp.Sheets("master").Select &&works fine
>oleApp.Sheets("master").Copy After:=Sheets(2) &&BOMBED
>oleApp.Sheets("master (2)").Select &&Didn't get this far
>oleApp.Sheets("master (2)").Name="38730" &&Didn't get this far
>
>Any suggestions are greatly appreciated.
>
>Thanks,
>Martha
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement