MACRO

Copper Contributor
I am needing assistance. This maybe somewhat common knowledge for some, however I am new to VBA.

I have one spreadsheet that I have written a macro to organize data how I need it. What I need to know is how to have the macro browse and open another excel file. Then place the data from one sheet to another.

Any help would be great!!

Thanks
1 Reply

@Airstrike117 

See if you can use this as a starting point. You'll have to modify it, of course.

Sub OpenWorkbook()
    Dim varFile As Variant
    Dim wbkCurrent As Workbook
    Dim wbkOther As Workbook
    ' Prompt user to select another workbook
    varFile = Application.GetOpenFilename(FileFilter:="Excel Workbooks (*.xls*),*.xls*")
    If VarType(varFile) = vbBoolean Then
        Beep
        Exit Sub
    End If
    ' Reference to the active workbook
    Set wbkCurrent = ActiveWorkbook
    ' Open the other workbook
    Set wbkOther = Workbooks.Open(varFile)
    ' Do something with the selected workbook
    wbkOther.Worksheets("Sheet1").Range("A1:C10").Copy Destination:=wbkCurrent.Worksheets("Sheet1").Range("A1")
    ' Close the other workbook
    wbkOther.Close SaveChanges:=False
End Sub