Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy a sheet from one workbook to another

Here's my code which does nothing. Generates no error, but doesn't copy the
sheet into the workbook. It does successfully rename the "Operations" sheet,
but is supposed to copy a sheet into the workbook in front of that one.

private void CopyTab(excel.Worksheet ws, excel.Workbook wb)
{
try
{
foreach (excel.Worksheet w in wb.Sheets)
{
if (w.Name.IndexOf("Operations") -1)
{
w.Copy(ws, Type.Missing); // copy ws into wb workbook
// gets no error, but doesn't do anything else either!
w.Name = "Operations (updated)";
break;
}
} // end foreach
}
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy a sheet from one workbook to another


cupboy;324242 Wrote:
Here's my code which does nothing. Generates no error, but doesn't copy
the
sheet into the workbook. It does successfully rename the "Operations"
sheet,
but is supposed to copy a sheet into the workbook in front of that
one.

private void CopyTab(excel.Worksheet ws, excel.Workbook wb)
{
try
{
foreach (excel.Worksheet w in wb.Sheets)
{
if (w.Name.IndexOf("Operations") -1)
{
w.Copy(ws, Type.Missing); // copy ws into wb workbook
// gets no error, but doesn't do anything else either!
w.Name = "Operations (updated)";
break;
}
} // end foreach
}

I can only assume that this is from a Windows Script file or something,
it looks like JavaScript or C. This forum is for VBA, so you may not get
a lot of help with it here. If you want to do this through Excel's VBA
it will be a lot easier!


--
gmorris
------------------------------------------------------------------------
gmorris's Profile: http://www.thecodecage.com/forumz/member.php?userid=245
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=90608

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Copy a sheet from one workbook to another

Try this:
Sub CopySheets()
Application.DisplayAlerts = False
Dim sh As Worksheet
Dim x As Integer

For Each sh In ActiveWorkbook.Worksheets
If InStr(1, sh.Name, "Operations") Then
sh.Select False
Else

For x = 1 To ActiveWorkbook.Sheets.Count - 1
ActiveWorkbook.Sheets(x).Copy _
After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets .Count)
Next

End If
Next sh
Application.DisplayAlerts = True
End Sub


Make a backup of your data before running any macro of any kind!!

HTH
Ryan---


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"gmorris" wrote:


cupboy;324242 Wrote:
Here's my code which does nothing. Generates no error, but doesn't copy
the
sheet into the workbook. It does successfully rename the "Operations"
sheet,
but is supposed to copy a sheet into the workbook in front of that
one.

private void CopyTab(excel.Worksheet ws, excel.Workbook wb)
{
try
{
foreach (excel.Worksheet w in wb.Sheets)
{
if (w.Name.IndexOf("Operations") -1)
{
w.Copy(ws, Type.Missing); // copy ws into wb workbook
// gets no error, but doesn't do anything else either!
w.Name = "Operations (updated)";
break;
}
} // end foreach
}

I can only assume that this is from a Windows Script file or something,
it looks like JavaScript or C. This forum is for VBA, so you may not get
a lot of help with it here. If you want to do this through Excel's VBA
it will be a lot easier!


--
gmorris
------------------------------------------------------------------------
gmorris's Profile: http://www.thecodecage.com/forumz/member.php?userid=245
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=90608


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy a sheet from one workbook to another


I'm sure that will work, but what if the OP is wanting to automate this
through Windows Scripting or some kind of addin? If that's the case, you
could still use VBScript (or JavaScript for that matter), but you would
have to create the Excel objects and all that, and he/she still hasn't
said how he/she is trying to accomplish this and may not even know how
to use VBA for all we know...


--
gmorris
------------------------------------------------------------------------
gmorris's Profile: http://www.thecodecage.com/forumz/member.php?userid=245
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=90608

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy sheet cells into differnt workbook/sheet, How? IVLUTA Excel Discussion (Misc queries) 2 June 2nd 09 11:16 PM
Copy rows from multiple workbook into a different workbook (sheet) Yossy Excel Programming 19 May 11th 08 12:34 AM
Copy Sheet from One workbook to another EXISTING workbook Ken Soenen Excel Programming 0 February 12th 06 04:07 PM
automatic copy and paste from sheet to sheet in a workbook ramseyjramseyj Excel Programming 6 December 11th 04 12:37 AM


All times are GMT +1. The time now is 10:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"