Copy from 2 Excel files into another

vgarzon

New Member
Joined
Dec 6, 2012
Messages
1
Hi,

I'm trying to include a button with a macro that opens a selected file, copies the data and pastes it on a Sheet of the original file.

I think I'm close, but when trying to paste I receive an error. I don't know if that's the correct way so I'm open to new ways of doing this.

The strange part is that If I stop on the pasting step and continue debugging step by step, it works fine.

See original post in: http://www.ozgrid.com/forum/showthread.php?t=172591


I'm using Excel 2010 and here's what I do:

Code:
Sub pasteFromFile() 
    Sheet15.Activate 
    Cells.ClearContents 
     'Open a user-selectable MS Excel file
    fileOpenName = Application.GetOpenFilename(filefilter:="MS Excel Files, *.xls;*.xlsx") 
     'fileSaveName = Application.GetSaveAsFilename(filefilter:="xlsx Files (*.xlsx), *.xlsx")
    If fileOpenName = False Then 
        MsgBox "Please select a valid MS Excel file to load" 
    Else 
        Application.ScreenUpdating = False 
        Application.DisplayAlerts = False 
         
        Dim obXL As Object 
         
        Set obXL = New Excel.Application 
        obXL.Visible = False 'True
        obXL.Workbooks.Open fileOpenName 
         'Copy the whole source sheet data
        Application.CutCopyMode = False 
        obXL.Cells.Copy 
         
         'Paste it on the destination tab
        Windows(1).Activate 
        Sheet15.Activate 
        Sheet15.Range("A1").Select 
        ActiveSheet.Paste 
         
        Application.CutCopyMode = False 
         
         'Close the background open file
        obXL.Quit 
         
         'Go back to the instructions
        Sheet18.Activate 
         
        Application.ScreenUpdating = True 
        Application.DisplayAlerts = True 
    End If 
     
End Sub
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,216,081
Messages
6,128,696
Members
449,464
Latest member
againofsoul

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