V
Vacuum Sealed
Hi Everyone
Is there a way that I can utilise the "FileToOpen" as a pointer for
activating a Workbook.
eg.
Sub ImportData()
ChDrive "T:\"
ChDir "T:\MyFolder"
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to import", _
FileFilter:="Excel Files *.xls (*.xls),")
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Doh!!!"
Exit Sub
Else
Workbooks.Open Filename:=FileToOpen
End If
Range("A5:AD201").Select
Selection.Copy
Windows(MyOtherWorkbook).Activate
Sheets("MySheet").Select
ActiveSheet.Paste
' This is the tricky bit, Once I have opened the "FileToOpen", and moved the
focus away from it to "MyOtherWorkbook, can I then use the "FileToOpen"
' statement inside the brackets to then re-establish the focus on the
Workbook that was opened originally.
Windows(FileToOpen).Activate
Either that, or have the file name Stamped/Inserted into the bracket.
eg.
If for instance, using the OpenDiagBox to get my file, I selected
"Duff_Beer", is there a handy line of code that can Imprint/Insert/Stamp
that between the brackets so the next instance of Windows().Activate could
be populated with Windows("Duff_Beer").Activate.
I only need to have this happen once, Although I will be copying data from
two locations and pasting to two locations in the target Workbook, I will be
copying the first range when I Open/Activate the Source, its the second
instance that is of concern, reason being is that I need to copy data from a
second sheet and paste to seperate locations in my target Workbook, so I
would need to activate the Source twice.
TIA
Mick
Is there a way that I can utilise the "FileToOpen" as a pointer for
activating a Workbook.
eg.
Sub ImportData()
ChDrive "T:\"
ChDir "T:\MyFolder"
FileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to import", _
FileFilter:="Excel Files *.xls (*.xls),")
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Doh!!!"
Exit Sub
Else
Workbooks.Open Filename:=FileToOpen
End If
Range("A5:AD201").Select
Selection.Copy
Windows(MyOtherWorkbook).Activate
Sheets("MySheet").Select
ActiveSheet.Paste
' This is the tricky bit, Once I have opened the "FileToOpen", and moved the
focus away from it to "MyOtherWorkbook, can I then use the "FileToOpen"
' statement inside the brackets to then re-establish the focus on the
Workbook that was opened originally.
Windows(FileToOpen).Activate
Either that, or have the file name Stamped/Inserted into the bracket.
eg.
If for instance, using the OpenDiagBox to get my file, I selected
"Duff_Beer", is there a handy line of code that can Imprint/Insert/Stamp
that between the brackets so the next instance of Windows().Activate could
be populated with Windows("Duff_Beer").Activate.
I only need to have this happen once, Although I will be copying data from
two locations and pasting to two locations in the target Workbook, I will be
copying the first range when I Open/Activate the Source, its the second
instance that is of concern, reason being is that I need to copy data from a
second sheet and paste to seperate locations in my target Workbook, so I
would need to activate the Source twice.
TIA
Mick