MGP
MGP

Reputation: 2551

Prompt User to open another workbook

I am writing a sub, where I need the user to open a specific workbook, because I need to copy data from the workbook that will be opened, to the workbook that is running the sub. Since the file that will be opened is a monthly report, it is difficult for the user to always save it in the same location with the same file name. Therefore it would be great if the user is asked to open the workbook (monthly report).

Upvotes: 0

Views: 1940

Answers (1)

A.S.H
A.S.H

Reputation: 29352

Function openMontlyReport() as Workbook
   MsgBox "Please select the monthly report in the next file dialog"
   With Application.FileDialog(msoFileDialogOpen)
     .Title = "Select Monthly Report"
     .Filters.Add "Excel Files", "*.*"
     .AllowMultiSelect = False
     If .Show Then Set openMontlyReport = Application.Workbooks.Open .SelectedItems(1)
   End With
End Function

Now you have at hand the monthly workbook that the user just opened.

Upvotes: 1

Related Questions