View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Activating Workbooks

fname is the complete path and file name. The code you have to activate
expects only the file name. So you can either parse out the file name with
instrev looking for the \ or easier still set a workbook object with makes
referncing easy...

Dim wbk As Workbook
Dim fName As String

fName = Application.GetOpenFilename()
on error resume next
Set wbk = Workbooks.Open(Filename:=fName)
on error goto 0
if wbk is nothing then
msgbox "No file opened"
exit sub
end if
ThisWorkbook.Activate
wbk.Activate



--
HTH...

Jim Thomlinson


"Sungibungi" wrote:

I have opened up a file using the following code:

Dim fName As String
fName = Application.GetOpenFilename()
Workbooks.Open Filename:=fName

Then I switch to a different workbook to, tranferring data. When done, I
need to go back to this "fName" worksheet.

The logical code (at least to me...) Worksheets(fName).activate obviously
doesn't seem to be working. How do I make this happen?

Thanks so much in advance.