#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Activating Workbooks

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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
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.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Activating Workbooks

Works like a charm. Thanks for the help.

"Jim Thomlinson" wrote:

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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
activating workbooks Ray Clark[_2_] Excel Discussion (Misc queries) 2 May 25th 09 04:25 AM
Activating a Macro d_kight New Users to Excel 5 June 30th 06 07:46 PM
Activating a Checkbox Lucille Excel Worksheet Functions 0 April 28th 06 06:22 PM
List box not activating sue74 Excel Discussion (Misc queries) 0 November 8th 05 01:34 PM
Activating a Hyperlink Jeremy S Excel Discussion (Misc queries) 3 July 3rd 05 02:15 AM


All times are GMT +1. The time now is 05:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"