+ Reply to Thread
Results 1 to 6 of 6

Activating a workbook you just opened

  1. #1
    Registered User
    Join Date
    09-19-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Activating a workbook you just opened

    This strip of code is designed to open all .raw delimited text files in a folder, delimit them, and save them in another folder in .xlsm format. The script runs in a blank workbook and opens a text file one at a time in another workbook.

    It gets as far as opening the first .raw file in the folder and then immediately failing. I am assuming that I am not properly activating the workbook I just opened.

    Note that I cut some of the code out that isn't relevant to this question.

    Please Login or Register  to view this content.
    If my assumption is correct, how do I properly activate the workbook?

    Thanks!
    Last edited by Dante_Blake; 09-20-2011 at 05:01 PM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Activating a workbook you just opened

    Is it failing when it opens the workbook or when you try to activate it?

    If you put a break-point in the code and step through which line generates the error?

  3. #3
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Activating a workbook you just opened

    I'd suggest modifying this line:
    Please Login or Register  to view this content.
    Change to:
    Please Login or Register  to view this content.
    My assumption is that Excel is looking for an object for the columns reference, in this case, a specified sheet.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  4. #4
    Registered User
    Join Date
    09-19-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Activating a workbook you just opened

    That change got me past that line. However, I am having the problem that every cell, column, etc... command wants sheets(1). before it.

    Is there a way to activate the sheet so that it assumes all commands are performed on that sheet without having to name it? Or is that not possible since I am running the code from a different workbook.

    Thanks!

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Activating a workbook you just opened

    What you could try:

    1. Dim a workbook variable at the start of your procedure:

    Please Login or Register  to view this content.

    2. Modify your open line to be:

    Please Login or Register  to view this content.

    3. Change your activate line to:

    Please Login or Register  to view this content.

    4. See if it works.

  6. #6
    Registered User
    Join Date
    09-19-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Activating a workbook you just opened

    Thanks for your suggestion but I was still getting errors. I went ahead and added sheets(1). to everything. I figure that's a good habit to get into anyway. The code runs fine, cycles through everything!

    Thanks again!

+ 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