ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy?import whole sheet from another workbook (https://www.excelbanter.com/excel-programming/367276-copy-import-whole-sheet-another-workbook.html)

justagrunt

Copy?import whole sheet from another workbook
 
Hi,
If I automate the opening of another workbook what is the way to copy the
whole worksheet and paste it to the current workbook?
Or should this be done by importing.
I realise that the worksheet will be overwriten.
I am working on a VBA code to ask a question if the current workbook needs
updating and if yes, then another workbooks worksheet is added.
This will then allow me to copy and paste ranges from one sheet to another
and update records automatically. I figure this is the only way to do it as
to have both workbooks open and selectively cut and paste from one book to
the other is beyond me.
--
Regards
Bill

Dove

Copy?import whole sheet from another workbook
 
The follwowing should work:

Sub Macro1()

Dim wsCurrent as Worksheet
Dim wbCopy as Workbook
Dim wbCurrent as Workbook
Dim x
Dim sYourFilename as String

x = MsgBox("Do You Wish to Update", vbYesNo, "Update?")
If x = vbYes Then
Set wbCurrent = ActiveWorkbook
Set wsCurrent = ActivveSheet

sYourFilename = "xxxxxxxx.xls" 'Replace with your filepath and
name

Workbooks.Open sYourFilename
Sheets("Sheet1").Activate 'Replace with your sheet
name
Cells.Select
Selection.Copy

wbCurrent.Activate
wsCurrent.Activate

Applicaiton.DisplayAlerts = False 'If you want to copy over any
existing data with no warning

ActiveSheet.Paste

wbCopy.Close
Application.DisplayAlerts = True

Set wbCurrent = Nothing
Set wbCopy = Nothing
Set wsCurrent = Nothing
End If

End Sub


"justagrunt" wrote in message
...
Hi,
If I automate the opening of another workbook what is the way to copy the
whole worksheet and paste it to the current workbook?
Or should this be done by importing.
I realise that the worksheet will be overwriten.
I am working on a VBA code to ask a question if the current workbook needs
updating and if yes, then another workbooks worksheet is added.
This will then allow me to copy and paste ranges from one sheet to another
and update records automatically. I figure this is the only way to do it
as
to have both workbooks open and selectively cut and paste from one book to
the other is beyond me.
--
Regards
Bill





All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com