MACRO

%3CLINGO-SUB%20id%3D%22lingo-sub-2311946%22%20slang%3D%22en-US%22%3EMACRO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2311946%22%20slang%3D%22en-US%22%3EI%20am%20needing%20assistance.%20This%20maybe%20somewhat%20common%20knowledge%20for%20some%2C%20however%20I%20am%20new%20to%20VBA.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20one%20spreadsheet%20that%20I%20have%20written%20a%20macro%20to%20organize%20data%20how%20I%20need%20it.%20What%20I%20need%20to%20know%20is%20how%20to%20have%20the%20macro%20browse%20and%20open%20another%20excel%20file.%20Then%20place%20the%20data%20from%20one%20sheet%20to%20another.%3CBR%20%2F%3E%3CBR%20%2F%3EAny%20help%20would%20be%20great!!%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2311946%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2312108%22%20slang%3D%22en-US%22%3ERe%3A%20MACRO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2312108%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1042090%22%20target%3D%22_blank%22%3E%40Airstrike117%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESee%20if%20you%20can%20use%20this%20as%20a%20starting%20point.%20You'll%20have%20to%20modify%20it%2C%20of%20course.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20OpenWorkbook()%0A%20%20%20%20Dim%20varFile%20As%20Variant%0A%20%20%20%20Dim%20wbkCurrent%20As%20Workbook%0A%20%20%20%20Dim%20wbkOther%20As%20Workbook%0A%20%20%20%20'%20Prompt%20user%20to%20select%20another%20workbook%0A%20%20%20%20varFile%20%3D%20Application.GetOpenFilename(FileFilter%3A%3D%22Excel%20Workbooks%20(*.xls*)%2C*.xls*%22)%0A%20%20%20%20If%20VarType(varFile)%20%3D%20vbBoolean%20Then%0A%20%20%20%20%20%20%20%20Beep%0A%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20End%20If%0A%20%20%20%20'%20Reference%20to%20the%20active%20workbook%0A%20%20%20%20Set%20wbkCurrent%20%3D%20ActiveWorkbook%0A%20%20%20%20'%20Open%20the%20other%20workbook%0A%20%20%20%20Set%20wbkOther%20%3D%20Workbooks.Open(varFile)%0A%20%20%20%20'%20Do%20something%20with%20the%20selected%20workbook%0A%20%20%20%20wbkOther.Worksheets(%22Sheet1%22).Range(%22A1%3AC10%22).Copy%20Destination%3A%3DwbkCurrent.Worksheets(%22Sheet1%22).Range(%22A1%22)%0A%20%20%20%20'%20Close%20the%20other%20workbook%0A%20%20%20%20wbkOther.Close%20SaveChanges%3A%3DFalse%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Occasional Visitor
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