Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default 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/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default 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

  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default 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/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

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
Copying and pasting links within the same workbook GEwan Excel Worksheet Functions 0 June 8th 09 05:50 PM
Copying/Linking Entire Workbook TomP Excel Discussion (Misc queries) 2 October 6th 08 10:09 PM
Copying store numbers and pasting them into a seperate workbook punter Excel Discussion (Misc queries) 2 May 26th 06 11:24 PM
Copying and pasting ??? NorcalTruck Excel Discussion (Misc queries) 3 December 27th 05 08:31 PM
Copying & Pasting Michael[_10_] Excel Programming 1 August 28th 03 11:00 AM


All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"