|
-
Feb 10th, 2006, 01:11 PM
#1
Thread Starter
New Member
[RESOLVED] Insert a spreadsheet from other workbook
How can I insert a spreadsheet from other workbook using VBA? Depending on parameters I would set a code to insert a certain spreadsheet from an external workbook. I just couldn't find the "insert" procedure.
-
Feb 10th, 2006, 01:25 PM
#2
Re: Insert a spreadsheet from other workbook
Excel VBA question moved to Office Development
-
Feb 10th, 2006, 01:56 PM
#3
Re: Insert a spreadsheet from other workbook
Would the source and target workbooks be open already or would you want the procedure to open them?
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 10th, 2006, 02:14 PM
#4
Frenzied Member
Re: Insert a spreadsheet from other workbook
I did a quick Macro Record and extracted the following:
Code:
Workbooks("Book1Name").Sheets("SheetName").Copy Before:=Workbooks("Book2Name").Sheets(1)
Workbooks("Book1Name").Sheets("SheetName").Move Before:=Workbooks("Book2Name").Sheets(1)
This requires that you specify all names explicitly ... you can substiture string variables with the names if you need to. This makes the Moved/Copied sheet the first sheet in the destination workbook. To make the Moved/Copied sheet the LAST sheet, just make the following substitution:
Code:
Sheets(1) >> Sheets(Workbooks("Book2Name").Sheets.Count)
You can make things easier by assigning handles to your Workbooks and Worksheets. Let me know if you need to know how to do that.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Feb 10th, 2006, 02:14 PM
#5
Re: Insert a spreadsheet from other workbook
IF both books are closed use the following...
VB Code:
Sub CopySheet(sSourcePath As String, sTargetPath As String, sSheetName As String)
Dim wkbSource As Workbook
Dim wkbTarget As Workbook
Dim lSheetCount As Long
Workbooks.Open Filename:=sSourcePath
Set wkbSource = ActiveWorkbook
Workbooks.Open Filename:=sTargetPath
Set wkbTarget = ActiveWorkbook
lSheetCount = wkbTarget.Sheets.Count
wkbSource.Worksheets(sSheetName).Copy After:=wkbTarget.Sheets(lSheetCount)
wkbSource.Close SaveChanges:=False
wkbTarget.Close SaveChanges:=True
Set wkbSource = Nothing
Set wkbTarget = Nothing
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 10th, 2006, 02:18 PM
#6
Thread Starter
New Member
Re: Insert a spreadsheet from other workbook
Thanks Kenny, I'try it. Target book will be open. The source will be closed.
Vladimir
-
Feb 10th, 2006, 02:57 PM
#7
Thread Starter
New Member
Re: Insert a spreadsheet from other workbook
Hi Kenny, it worked. I have changed it a little bit.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|