Macro to open specific folder

Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
194
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

I have the macro below on a button in a worksheet and I want it to open "C:\Users\HOME\Dropbox\DSR DAILY IMPORT" so we can select a file
which it does BUT it also opens "My Documents" folder as well? I'm not seeing why that is happening?

Thank you!


Code:
​[COLOR=#333333]Sub Macro1()[/COLOR]<code style="font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; line-height: 12px;">'
' Macro1 Macro()

Dim MyFolder As String
MyFolder = "C:\Users\HOME\Dropbox\DSR DAILY IMPORT"
ActiveWorkbook.FollowHyperlink MyFolder
Dim wkbCrntWorkBook As Workbook
Dim wkbSourceBook As Workbook
Dim rngSourceRange As Range
Dim rngDestination As Range
Set wkbCrntWorkBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa; *.csv"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set wkbSourceBook = ActiveWorkbook
Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1:I400", Type:=8)
wkbCrntWorkBook.Activate
Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)
rngSourceRange.Copy rngDestination
wkbSourceBook.Close False
End If
End With
End Sub</code>
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try:
Code:
Sub Buns()
    Dim MyFolder As FileDialog, FileChosen As Integer, FileName As String, wkbSourceBook As Workbook, wkbCrntWorkBook As Workbook
    Dim rngSourceRange As Range, rngDestination As Range
    Set wkbCrntWorkBook = ActiveWorkbook
    Set MyFolder = Application.FileDialog(msoFileDialogFilePicker)
    MyFolder.InitialFileName = "C:\Users\HOME\Dropbox\DSR DAILY IMPORT\"
    FileChosen = MyFolder.Show
    FileName = MyFolder.SelectedItems(1)
    Set wkbSourceBook = Workbooks.Open(FileName)
    Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1:I400", Type:=8)
    wkbCrntWorkBook.Activate
    Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)
    rngSourceRange.Copy rngDestination
    wkbSourceBook.Close False
End Sub
 
Upvote 0
Mumps,

ABSOLUTE Genius!! I've been beating my noggin against the wall for a day on that macro.

Thank you very much!!
 
Upvote 0
Hi Mumps,

The macro below is very similar to the one from yesterday and I tried editing it but no luck. Wonder if you might have a look at it please?
There are multiple sheets in this workbook so the destination sheets are key.

Thank you!!



Code:
Sub IMPORT_PLUs()    Dim wkbCrntWorkBook As Workbook
    Dim wkbSourceBook As Workbook
    Dim rngSourceRange As Range
    Dim rngDestination As String
    Set wkbCrntWorkBook = ActiveWorkbook
    With Application.FileDialog(msoFileDialogOpen)
        .Filters.Clear
        .Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa; *.csv"
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            Workbooks.Open .SelectedItems(1)
            Set wkbSourceBook = ActiveWorkbook
            Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1:H500", Type:=8)
            wkbCrntWorkBook.Activate
            rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1")
            rngSourceRange.Copy Sheets("POS IMPORT").Range(rngDestination)
            Sheets("POS IMPORT").Columns.AutoFit
            wkbSourceBook.Close False
        End If
    End With
End Sub
 
Upvote 0
Please explain in detail how it is not working for you. Do you get any error messages. If so what is the message and which line of code is highlighted when you click "Debug"?
 
Upvote 0
Hi Mumps,
Sorry I probably wasn't clear. The code I posted last works with the exception of opening the folder we want to pick the file from
which is "C:\Users\HOME\Dropbox\LOTTERY-PLU DAILY IMPORT".

Thank you!
 
Upvote 0
Does the macro I suggested not work for you? In that macro you can set the desired folder with this line of code:
Code:
MyFolder.InitialFileName = "C:\Users\HOME\Dropbox\LOTTERY-PLU DAILY IMPORT\"
 
Upvote 0
Hi Mumps,

The macro is hanging up on the the 2 lines

Code:
"rngSourceRange.Copy Sheets("POS IMPORT").Range(rngDestination)  
  Sheets("POS IMPORT").Columns.AutoFit"
 
Last edited:
Upvote 0
This seems to work:
Code:
Sub Buns()
    Dim MyFolder As FileDialog, FileChosen As Integer, FileName As String, wkbSourceBook As Workbook, wkbCrntWorkBook As Workbook
    Dim rngSourceRange As Range, rngDestination As Range
    Set wkbCrntWorkBook = ActiveWorkbook
    Set MyFolder = Application.FileDialog(msoFileDialogFilePicker)
    MyFolder.InitialFileName = "C:\Users\HOME\Dropbox\LOTTERY-PLU DAILY IMPORT\"
    FileChosen = MyFolder.Show
    FileName = MyFolder.SelectedItems(1)
    Set wkbSourceBook = Workbooks.Open(FileName)
    Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1:I400", Type:=8)
    wkbCrntWorkBook.Activate
    Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)
    rngSourceRange.Copy rngDestination
    Sheets("POS IMPORT").Columns.AutoFit
    wkbSourceBook.Close False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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