![]() |
Copying and pasting entire workbook
Hi,
I'm trying to write a load function which loads a workbook, copies it contents, closes it and pastes the copied information into the workboo that was open all the time (replacing what is already in there). can't figure out how to do it. I really don't want to copy/paste i sheet by sheet. This is what I have: Code ------------------- Dim sFname As String sFname = Application.GetOpenFilename( _ FileFilter:="Excel Workbooks,*.xls", _ Title:="Open a File", _ MultiSelect:=False) If sFname < "False" Then Workbooks.Open sFname Workbooks(2).Worksheets.Copy Workbooks(2).Close False ' This is what I would like to be able to do. Workbooks(1).Worksheets.Paste End If ------------------- Any ideas? Thanks in advance -- Message posted from http://www.ExcelForum.com |
Copying and pasting entire workbook
Why not just copy the file?
RBS "phreud " wrote in message ... Hi, I'm trying to write a load function which loads a workbook, copies its contents, closes it and pastes the copied information into the workbook that was open all the time (replacing what is already in there). I can't figure out how to do it. I really don't want to copy/paste it sheet by sheet. This is what I have: Code: -------------------- Dim sFname As String sFname = Application.GetOpenFilename( _ FileFilter:="Excel Workbooks,*.xls", _ Title:="Open a File", _ MultiSelect:=False) If sFname < "False" Then Workbooks.Open sFname Workbooks(2).Worksheets.Copy Workbooks(2).Close False ' This is what I would like to be able to do. Workbooks(1).Worksheets.Paste End If -------------------- Any ideas? Thanks in advance! --- Message posted from http://www.ExcelForum.com/ |
Copying and pasting entire workbook
The file contains a large number of UserForms, making the file over 500
kB in size. I've written a save function that copy just the worksheets and saves them (making saved files about 80 kB). The problem is when I'm trying to load them again. I want to compltetely replace everything in the open workbook with the contents of the workbook in the saved file. I just can't get it to work, been struggeling with it for 5 hrs now :( I can load the saved file and paste it into a new workbook, but I can't paste it into an existing one. Any help would be greatly apprechiated! --- Message posted from http://www.ExcelForum.com/ |
Copying and pasting entire workbook
Workbooks(2).Worksheets.Copy _
after:=workbooks(1).worksheets(1) will copy the sheets to workbooks(1). "phreud <" wrote: Hi, I'm trying to write a load function which loads a workbook, copies its contents, closes it and pastes the copied information into the workbook that was open all the time (replacing what is already in there). I can't figure out how to do it. I really don't want to copy/paste it sheet by sheet. This is what I have: Code: -------------------- Dim sFname As String sFname = Application.GetOpenFilename( _ FileFilter:="Excel Workbooks,*.xls", _ Title:="Open a File", _ MultiSelect:=False) If sFname < "False" Then Workbooks.Open sFname Workbooks(2).Worksheets.Copy Workbooks(2).Close False ' This is what I would like to be able to do. Workbooks(1).Worksheets.Paste End If -------------------- Any ideas? Thanks in advance! --- Message posted from http://www.ExcelForum.com/ -- Dave Peterson |
Copying and pasting entire workbook
Dave Peterson wrote:
*Workbooks(2).Worksheets.Copy _ after:=workbooks(1).worksheets(1) will copy the sheets to workbooks(1). Dave Peterson * The thing is, I need to replace the sheets in workbooks(1) with th corresponding sheets in workbooks(2), not just paste them as ne sheets. I have a working (but really ugly) solution. I can copy and paste cel by cell, and everything in the workbook (graphs etc) get update correctly. This is what I have now: Code ------------------- Workbooks.Open sFname Workbooks(2).Worksheets("Sheet1").Range("C11").Cop y Workbooks(1).Worksheets("Sheet1").Range("C11").Pas teSpecial Transpose:=True Workbooks(2).Close False ------------------- I want to do this for all cells in all worksheets. Thankyou -- Message posted from http://www.ExcelForum.com |
Copying and pasting entire workbook
Phreud,
It seems you could loop through the sheets in the "from" book, deleting the corresponding named sheet from the "to" book and then copying it to the "to" book. Sub test() Dim from_ws As Worksheet Dim to_wb As Workbook Set to_wb = Workbooks("to.xls") On Error GoTo err_handler Application.ScreenUpdating = False Application.DisplayAlerts = False For Each from_ws In Workbooks("from.xls").Worksheets to_wb.Sheets(from_ws.Name).Delete from_ws.Copy after:=to_wb.Worksheets(to_wb.Worksheets.Count) Next from_ws err_handler: Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub hth, Doug "phreud " wrote in message ... Hi, I'm trying to write a load function which loads a workbook, copies its contents, closes it and pastes the copied information into the workbook that was open all the time (replacing what is already in there). I can't figure out how to do it. I really don't want to copy/paste it sheet by sheet. This is what I have: Code: -------------------- Dim sFname As String sFname = Application.GetOpenFilename( _ FileFilter:="Excel Workbooks,*.xls", _ Title:="Open a File", _ MultiSelect:=False) If sFname < "False" Then Workbooks.Open sFname Workbooks(2).Worksheets.Copy Workbooks(2).Close False ' This is what I would like to be able to do. Workbooks(1).Worksheets.Paste End If -------------------- Any ideas? Thanks in advance! --- Message posted from http://www.ExcelForum.com/ |
Copying and pasting entire workbook
Thanks Doug!
I'll look into that tomorrow. Looks like it could work. I'll get bac with results.. -- Message posted from http://www.ExcelForum.com |
All times are GMT +1. The time now is 02:54 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com