Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default importing worksheet via code

How do I import a worksheet from an existing .xls file to a spreadsheet that
is currently open and active?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default importing worksheet via code

Hi Willie,

If both workbooks are open, then try:

'========================
Sub Tester04()
Dim destWB As Workbook
Dim srcWB As Workbook

Dim sh As Worksheet

Set destWB = ActiveWorkbook
Set srcWB = Workbooks("TEST1.xls")'<<===== CHANGE

Set sh = srcWB.Sheets("sheet1") '<<===== CHANGE

Application.ScreenUpdating = False

With destWB
sh.Copy after:=.Sheets(.Sheets.Count)
End With

Application.ScreenUpdating = True

End Sub
'<<========================


If the source workbook is closed. try:

'========================
Sub Tester05()

Dim destWB As Workbook
Dim srcWB As Workbook
Dim MyPath As String
Dim sName As String
Dim sh As Worksheet

Set destWB = ActiveWorkbook

MyPath = _
"C:\Documents and Settings\User\My Documents" '<<= CHANGE

sName = "TEST1.xls" '<<===== CHANGE

Set srcWB = Workbooks.Open(MyPath & "\" & sName)

Set sh = srcWB.Sheets("sheet1") '<<===== CHANGE

Application.ScreenUpdating = False

With destWB
sh.Copy after:=.Sheets(.Sheets.Count)
End With
srcWB.Close (False)

Application.ScreenUpdating = True

End Sub
'<<========================

Change the source workbook name , the sheet name and the path as
appropriate.

---
Regards,
Norman



"Willie Smith" wrote in message
om...
How do I import a worksheet from an existing .xls file to a spreadsheet
that is currently open and active?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default importing worksheet via code

Thanks, just what I wanted
"Norman Jones" wrote in message
...
Hi Willie,

If both workbooks are open, then try:

'========================
Sub Tester04()
Dim destWB As Workbook
Dim srcWB As Workbook

Dim sh As Worksheet

Set destWB = ActiveWorkbook
Set srcWB = Workbooks("TEST1.xls")'<<===== CHANGE

Set sh = srcWB.Sheets("sheet1") '<<===== CHANGE

Application.ScreenUpdating = False

With destWB
sh.Copy after:=.Sheets(.Sheets.Count)
End With

Application.ScreenUpdating = True

End Sub
'<<========================


If the source workbook is closed. try:

'========================
Sub Tester05()

Dim destWB As Workbook
Dim srcWB As Workbook
Dim MyPath As String
Dim sName As String
Dim sh As Worksheet

Set destWB = ActiveWorkbook

MyPath = _
"C:\Documents and Settings\User\My Documents" '<<= CHANGE

sName = "TEST1.xls" '<<===== CHANGE

Set srcWB = Workbooks.Open(MyPath & "\" & sName)

Set sh = srcWB.Sheets("sheet1") '<<===== CHANGE

Application.ScreenUpdating = False

With destWB
sh.Copy after:=.Sheets(.Sheets.Count)
End With
srcWB.Close (False)

Application.ScreenUpdating = True

End Sub
'<<========================

Change the source workbook name , the sheet name and the path as
appropriate.

---
Regards,
Norman



"Willie Smith" wrote in message
om...
How do I import a worksheet from an existing .xls file to a spreadsheet
that is currently open and active?





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
Importing Alan Beban's code on Arrays; Importing a module or a project Steve G Excel Worksheet Functions 4 August 27th 07 04:18 PM
Importing Uni Code (Big-Endian) Text data Qazi Imran Excel Discussion (Misc queries) 0 December 26th 06 09:14 AM
Removing & Importing user forms via code? R-Enemy[_3_] Excel Programming 2 December 16th 04 11:13 PM
Three short questions regarding importing of data. See code Susan Hayes Excel Programming 3 August 15th 04 04:17 PM
Importing Code into 'ThisWorkbook' Mark Excel Programming 3 April 16th 04 03:29 PM


All times are GMT +1. The time now is 02:42 AM.

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"