ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select File Copy/Paste Macro Help.... (https://www.excelbanter.com/excel-programming/287834-select-file-copy-paste-macro-help.html)

Jay Baker

Select File Copy/Paste Macro Help....
 
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
_________________


---
Message posted from http://www.ExcelForum.com/


Jay Baker[_2_]

Select File Copy/Paste Macro Help....
 
The GetOpenFile method part of the macro works fine, however when I try
to use that newly opened file, I get a runtime error 91...

Any ideas....:(

Jay


---
Message posted from http://www.ExcelForum.com/



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

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