![]() |
Copy from one workbook to another
I am trying to create a macro that is asigned to a button. When you
press the button I want it to let you navigate to the workbook you want, then when you open the desired workbook it copies and paste specials (values and number formats) all of sheet 1 from the workbook you navigated to into sheet 1 of the workbook that the button is in. Any help with the code to at least point me in the right direction would be greatly appreciated. Thanks |
Copy from one workbook to another
Put the following in a regular Module.
Public Sub CopySheet1() Dim str1 As String Dim iRtn As Integer Dim wb As Workbook Dim rng As Range iRtn = MsgBox("Are you sure you want to copy to a non-empty sheet?", vbYesNo) If iRtn = vbNo Then Exit Sub str1 = Application.GetOpenFilename("Excel files, *.xls") Set wb = Workbooks.Open(str1) Set rng = wb.Sheets("Sheet1").UsedRange rng.Copy ThisWorkbook.Activate Sheets("Sheet1").Activate Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("A1").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False wb.Close End Sub Hth, Merjet |
All times are GMT +1. The time now is 03:24 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com