Open a new file using a dialog box pop up without specifying the path of the file

Exceluser15

New Member
Joined
Jul 17, 2015
Messages
4
Hello Everyone,

I need help in writing a code which does the following:

1. Open /pop up a dialog box which asks the user to select a file from the computer

2. Copy paste the data from a worksheet in another workbook (say workbook A) to this newly opened workbook

I am not the only person who will be using this macro. It is going to be used by many others.
Hence, specifying the path of the file might not be useful as it might give " Out of range " error.

Please advise.

Thank you ,
Exceluser15
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this:

Code:
Dim FileToOpen As String
Dim wbA, wbB As Workbook
Set wbA = ActiveWorkbook
        FileToOpen= Application.GetOpenFilename("All Excel Files (*.xl*)," & _
        "*.xl*", 1, "Select workbook...", "Open", False)
            If TypeName(FileToOpen) = "Boolean" Then
                MsgBox "No file selected. Process will end."
                Exit Sub
            End If
Set wbB = ActiveWorkbook

This establishes the first workbook as wbA, asks you to open a 2nd workbook and establishes it as wbB.

From there, you can write your code using the wbA & wbB designations for copying and pasting data:

Code:
'For example
wbA.Sheets(1).Range("A1:A5").Copy Destination:=wbB.Sheets(1).Range("A1")
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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