+ Reply to Thread
Results 1 to 12 of 12

Opening a workbook then switching back to first workbook

  1. #1
    Forum Contributor
    Join Date
    04-03-2009
    Location
    USA, California
    MS-Off Ver
    Excel 2007
    Posts
    385

    Opening a workbook then switching back to first workbook

    I am trying to make one of my macros open a file then switch back to the orignal file and then running the macro.

    here is my code:

    Please Login or Register  to view this content.
    Last edited by randell.graybill; 04-30-2009 at 10:08 PM.

  2. #2
    Forum Contributor
    Join Date
    04-03-2009
    Location
    USA, California
    MS-Off Ver
    Excel 2007
    Posts
    385

    Re: Opening a workbook then switching back to first workbook

    Please Login or Register  to view this content.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Opening a workbook then switching back to first workbook

    It's not clar what you are doing, what is your code intended to do? The line to open a workbook is not used.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor
    Join Date
    04-03-2009
    Location
    USA, California
    MS-Off Ver
    Excel 2007
    Posts
    385

    Re: Opening a workbook then switching back to first workbook

    Well all I want to do is open "C:\Documents and Settings\randell.graybill.DOMAIN99\My Documents\17Cycle Count Logs.xls".

    Then switch back to the workbook that the macro was invoked from.

    As far as what the rest of the macro does, is it formats the data from the workbook the macro was invoked from deletes bunk data moves it to 17Cycle Count Logs.xls then closes the workbook the macro was run on.

    And thanks for taking the time to reply

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Opening a workbook then switching back to first workbook

    Something like this
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    04-03-2009
    Location
    USA, California
    MS-Off Ver
    Excel 2007
    Posts
    385

    Re: Opening a workbook then switching back to first workbook

    I get the follow error message with your code:

    Please Login or Register  to view this content.
    I don't get this error if I don't try to open 17Cycle Count Logs before I run the rest of the code.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Opening a workbook then switching back to first workbook

    That has nothing to do with my code. The code that i gave you does exactly what you asked - opens the workbook then activates the workbook containing the code.

  8. #8
    Forum Contributor
    Join Date
    04-03-2009
    Location
    USA, California
    MS-Off Ver
    Excel 2007
    Posts
    385

    Re: Opening a workbook then switching back to first workbook

    Why do I not get that error without the coded to open the other workbook then if it has nothing to do with the code trying to open the workbook?

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Opening a workbook then switching back to first workbook

    maybe your code is looking for a range in the newly opened workbook. Not sure without working my way through all the code. This doesn't specify which workbook you are using
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Opening a workbook then switching back to first workbook

    Try to do so:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  11. #11
    Registered User
    Join Date
    04-26-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Opening a workbook then switching back to first workbook

    try this

    Workbooks.Open Filename:="C:\Documents and Settings\randell.graybill.DOMAIN99\My Documents\17Cycle Count Logs.xls"

    windows("macro file name").activate

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Opening a workbook then switching back to first workbook

    Quote Originally Posted by pradeesh View Post
    try this

    Workbooks.Open Filename:="C:\Documents and Settings\randell.graybill.DOMAIN99\My Documents\17Cycle Count Logs.xls"

    windows("macro file name").activate
    Please wrap your code with Code Tags

    windows("macro file name").activate - this is the workbook containing the code which can be referred to as ThisWorkBook!

+ 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