+ Reply to Thread
Results 1 to 4 of 4

Switching between workbooks

  1. #1
    Registered User
    Join Date
    02-15-2006
    Posts
    93

    Switching between workbooks

    Good evening,

    I am trying to import data from one workbook into another but it is not working. Any ideas on what is happening? This is something I am piecing together from other posts but I have hit a snag.

    Please Login or Register  to view this content.
    It works up until Windows(CFileName).activate
    I am not sure what is happening here as I have checked, using a message box, and CFileName still has the correct file name. For some reason excel will not switch to the other file. If I switch this to Windows("Workbooks name.xls").activate the code works.

    Any ideas? As always, thank you in advance for your help!
    tc
    Last edited by mudraker; 09-23-2007 at 02:15 AM.

  2. #2
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    hi TC,
    You may have solved your problem by now but here is a revised macro with some possible changes...

    Please Login or Register  to view this content.
    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  3. #3
    Registered User
    Join Date
    02-15-2006
    Posts
    93
    Hi Rob,

    Thanks for your help. I didn't manage to get option 1 working but option 2 works great. Just out of curiousity, why did you use Select Case instead of an if then statement.

    Just trying to figure out if I should be use the Select Case feature more often.

    Thanks again!
    tc

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    HI TC,

    Thanks for the feedback, I'm pleased I could help :-)

    I used Select Case b/c I've got into the habit of using it rather than If statements recently - I've read in various places (*) that the Select Case approach can be quicker b/c:
    it only evaluates the first case which is true (therefore try & place the most common "Case" first in the list), completes the action, & then ends the Select compared with an If statement where both the True & the False "checks" (for want of a better word) are evaluated every time.

    The impact isn't that great in a situation such as this where there are only 2 possible options which are only being used once but can add up if you are using an If-Then-If-Then... structure or looping repeatedly through the code.

    One looking at the code I gave you it would probably be better around the other way to place the most common option first ie:

    Please Login or Register  to view this content.
    * not that I can find them again! anyway, see below for 2 links - when googling I found these but couldn't find the ones I've seen in the past:

    HTML Code: 
    HTML Code: 
    (esp the links at the base of this page)

    For general ss tips you may find the LH tab ("Excel Pages") on the following link to contain some useful background:
    HTML Code: 
    hth
    Rob

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1