hi all,
I've created a VBA code that imports part of a workbook into a reporting spreadsheet. this works really well until users decide to change the sheets.
The code is quite extensive so I will just post the relevant part of it.
'Open source file
Dim fNameAndPath As Variant
fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Template file To Be Open")
If fNameAndPath = False Then Exit Sub
Workbooks.Open Filename:=fNameAndPath
Dim w As Workbook
Set w = ActiveWorkbook
'Copy data from source file
' Copy index data
w.Activate
Sheets("Index").Visible = True
Sheets("Index").Select
Range("A11:H250").Select
Selection.Copy
WRK.Activate
Sheets(NewMC).Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
Application.CutCopyMode = False
This is the current code and as I said it works fine. The problem is, that users (and I can't stop them because they are the managers) keep adding sheets or change the name of the sheet so I can't rely on "Sheet1" or "sheet name".
My question is,
What is the code to be added that will allow the person making the importing exercise to select the tab where the information is instead of the current code that automatically selects the tab?
Thank you for looking and all the help is much appreciated.
Husoi
I've created a VBA code that imports part of a workbook into a reporting spreadsheet. this works really well until users decide to change the sheets.
The code is quite extensive so I will just post the relevant part of it.
'Open source file
Dim fNameAndPath As Variant
fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Template file To Be Open")
If fNameAndPath = False Then Exit Sub
Workbooks.Open Filename:=fNameAndPath
Dim w As Workbook
Set w = ActiveWorkbook
'Copy data from source file
' Copy index data
w.Activate
Sheets("Index").Visible = True
Sheets("Index").Select
Range("A11:H250").Select
Selection.Copy
WRK.Activate
Sheets(NewMC).Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
Application.CutCopyMode = False
This is the current code and as I said it works fine. The problem is, that users (and I can't stop them because they are the managers) keep adding sheets or change the name of the sheet so I can't rely on "Sheet1" or "sheet name".
My question is,
What is the code to be added that will allow the person making the importing exercise to select the tab where the information is instead of the current code that automatically selects the tab?
Thank you for looking and all the help is much appreciated.
Husoi