J
Jay Baker
I'm trying to setup a macro that allows the user to select a file and it
will then copy/paste from that file to Thisworkbook. The following
gives me an error:
Sub Macro1()
Dim wbkData As Workbook, wsData As Worksheet
Dim fn As Variant
fn = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select File To Open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
' the user didn't select a file
Debug.Print "Selected file: " & fn
Workbooks.Open fn
Set wsData = wbkData.Sheets("Sheet1")
Application.ScreenUpdating = False
With ThisWorkbook.Sheets("Sheet1")
wsData.Range("a1:a5").Copy Destination:=.Range("a1")
wsData.Range("b1:b5").Copy Destination:=.Range("b1")
wsData.Range("c1:c5").Copy Destination:=.Range("c1")
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
'do the copying
End Sub
I would also like to add a line which will run the copy/paste on ALL
sheets that have the same tab name.
Any ideas would be greatly appreciated,
Jay
_________________
will then copy/paste from that file to Thisworkbook. The following
gives me an error:
Sub Macro1()
Dim wbkData As Workbook, wsData As Worksheet
Dim fn As Variant
fn = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select File To Open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
' the user didn't select a file
Debug.Print "Selected file: " & fn
Workbooks.Open fn
Set wsData = wbkData.Sheets("Sheet1")
Application.ScreenUpdating = False
With ThisWorkbook.Sheets("Sheet1")
wsData.Range("a1:a5").Copy Destination:=.Range("a1")
wsData.Range("b1:b5").Copy Destination:=.Range("b1")
wsData.Range("c1:c5").Copy Destination:=.Range("c1")
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
'do the copying
End Sub
I would also like to add a line which will run the copy/paste on ALL
sheets that have the same tab name.
Any ideas would be greatly appreciated,
Jay
_________________