(Solved) – set variable for selected workbook through filepath

  • by

i want to select a workbook from a folder and apply my code to it, however i am unsure of how to set a variable for it.

i have this code that selects the workbook from the folder

Private Sub CommandButton1_Click()
Dim fileNameAndPath As Variant
fileNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Select File To Be Opened")
If fileNameAndPath = False Then Exit Sub
Workbooks.Open Filename:=fileNameAndPath

End Sub

how do i set a variable like

 Set wscopy = Workbooks("testing.xls").Worksheets("Report")

but with the testing.xls being the workbook chosen

thanks in advance !

Leave a Reply

Your email address will not be published. Required fields are marked *