copypaste from workbook to another

enzzz88

New Member
Joined
Sep 25, 2018
Messages
5
Hi guys,

i am a newbie to vba and i am trying to copy several worksheets from a closed file into my current open one.

the code is the following


Sub Import()


'copy data from closed workbook to active workbook


Dim xlApp As Application
Dim xlBook As Workbook
Dim wb1 As Workbook
Dim Sh As Object
Dim report As String


Set xlApp = CreateObject("Excel.Application")
'Path source workbook

Application.FileDialog(msoFileDialogFilePicker).Show
report = Application.FileDialog(msoFileDialogFilePicker).SelectedItems(1)


Set xlBook = xlApp.Workbooks.Open(report)

xlBook.Worksheets("WC_holiday_provision").UsedRange.Copy
xlApp.DisplayAlerts = False
Set wb1 = Workbooks("CZ_Payroll_Macro.xlsb")
Set Sh = wb1.Worksheets("WC_holiday_provision")
Sh.Activate
wb1.Worksheets("WC_holiday_provision").Range("A1").Select
Sh.Paste


Now, i would like to get rid of the SH.ACTIVATE and SH.PASTE and paste directly withouth having to activate every sheet window, any ideas?

thanks a lot:)
 
And two more corrections:
Rich (BB code):
Private Function LastRow(ByRef wks As Worksheet) As Long


    With wks
        LastRow = .Cells.Find("*", .Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious).Row
    End With
    
End Function


Private Function LastCol(ByRef wks As Worksheet) As Long


    With wks
        LastCol = .Cells.Find("*", .Cells(1, 1), xlFormulas, xlPart, xlByColumns, xlPrevious).Column
    End With
    
End Function
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top