PDA

View Full Version : Importing a worksheet



hsduk101
03-10-2007, 12:13 AM
All,

Im want to import sheet2 from workbook B into sheet1 in workbook A.

How do I do this. I was thinking of using the Application.Dialogs(xlDialogOpen) Function.

The reason that I want to use the xlDialogueOpen is because the sheet I am importing is not fixed and can be from any file.

As I said earlier I only want to import a sheet and not the entire workbook.

Also If I could choose which sheet I want to import then that would be better

Please help, I am a novice at VBA

lucas
03-10-2007, 10:48 AM
This can be done easily without vba by just opening both workbooks and right clicking on the sheet tab you wish to copy and select the workbook you wish to copy it to....

This will do it with vba but it does not give you the option to select which sheet to import....its coded in to select sheet 2
Sub a()
Dim sFileName As String
'Show the open dialog and pass the selected _
file name to the String variable "sFileName"
sFileName = Application.GetOpenFilename
'They have cancelled.
If sFileName = "False" Then Exit Sub

Workbooks.Open Filename:=sFileName
Sheets("Sheet2").Copy After:=Workbooks("master.xls").Sheets(ThisWorkbook.Sheets.Count)
Workbooks("data.xls").Close
End Sub

malik641
03-10-2007, 01:48 PM
Cross-posted:
http://www.vbforums.com/showthread.php?t=456973

hsduk101, please notify us when you post your questions to multiple forums. It's not fair for someone to work on your problem not knowing you may have your solution already.