copy to the same workbook

  • Thread starter Thread starter Alexander Bogomolny
  • Start date Start date
A

Alexander Bogomolny

Hello:

When "Copy or Move" sheet, in the dialog there is an opportunity to
define a workbook to copy the sheet to. However if I created a macro, it
does not reflect my choice, i.e., it comes the same whether I define or
not define a workbook.

Furthermore, when I run the created macro

Sheets("sheet").copy

the first time, it places a copy of sheet "sheet" as "sheet (2)" in the
same book. However, when run the second time it creates a new workbook
without my meaning to.

My question: is there a way to specify in the macor the workbook a sheet
is to be copied to.

Thank you,
Alex
 
Hello.

You need to specifically state the workbook object that is
your destination... like this:

Workbooks("Book3").Sheets("Sheet1").Copy After:=Workbooks
("Book2").Sheets(1)


the "Book3" would be your workbook's name, or it could be
better to use a workbook object to do it.

But, it's the "After" parameter that you need to set to do
what you're trying to do.
 
Mark, thank you.

You see, I do that from inside Java. For me it looks like

Sheets sheets = Workbook.getSheets();
Sheet sheet = sheets.getItem("sheet");
sheet.copy(sheet);

where the argument sheet in the copy method means "Before", which I
presume as suitable as "After" to my ends. So inside the parentheses a
sheet is a sheet (that came from a certain workbook.) There is no way
for me to specify sheets as an additional argument.

I would expect that something like

sheet.activate();

would work, but it does not.

In fact, I never want a second book, but only the one I start with.
Should not there be a default somewhere?

Thank you,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top