ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I copy a worksheet form a workbook in my workbook (https://www.excelbanter.com/excel-programming/342535-how-do-i-copy-worksheet-form-workbook-my-workbook.html)

Neil Atkinson

How do I copy a worksheet form a workbook in my workbook
 

Hi am using the following code to open a workbook

sFileName = Application.GetOpenFilename
If sFileName = "False" Then Exit Sub
Workbooks.Open sFileName

I need to copy sheet2 from the open workbook into the workbook that is
running the above code.

Also another thought if the workbook mentioned above is already open
what is the code to stop an error showing and activating the open
workbook?

Many Thanks
Neil

*** Sent via Developersdex http://www.developersdex.com ***

Joe HM

How do I copy a worksheet form a workbook in my workbook
 
Hello -

The following will check whether an Excel file called aName is already
open ...

For Each lWorkbook In Workbooks
If lWorkbook.Name = aName Then
lResult = MsgBox(aName & " is already open")
...
End If
Next lWorkbook

The next code snippet will copy the specified Worksheet into a new
workbook and save it ...

ThisWorkbook.Sheets("Sheet1").Select
ThisWorkbook.Sheets("Sheet1").Copy
ActiveWorkbook.SaveAs Filename:="C:\X.xls", FileFormat:=xlNormal

Joe



All times are GMT +1. The time now is 03:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com