+ Reply to Thread
Results 1 to 15 of 15

application.activewindow issue

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    application.activewindow issue

    Hi

    I have wrriten a macro which sits inside one workbook and should look at the second open workbook and go into one of the sheets and add column headers to the columns.

    However when it runs it keeps produing a "Type Mismatch" error

    Please Login or Register  to view this content.
    Does anyone know why this is happing?

    Thanks

    Jeskit
    Last edited by jeskit; 06-16-2011 at 12:00 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: application.activewindow issue

    This:
    Please Login or Register  to view this content.
    should be:
    Please Login or Register  to view this content.
    since you declared the variable as a Workbook, not a Window.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: application.activewindow issue

    Hey! I actually noticed that! I must be learning something here.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: application.activewindow issue



    Ok buts now changed to another error of "Subscript out of range" on the line

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor Sadath31's Avatar
    Join Date
    03-02-2011
    Location
    Dammam, Saudi Arabia
    MS-Off Ver
    Office 365
    Posts
    452

    Re: application.activewindow issue

    should be

    Please Login or Register  to view this content.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: application.activewindow issue

    Then the sheet name is incorrect. Perhaps there's a space in there?

  7. #7
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: application.activewindow issue

    Sorry i forgot to say that i changed the two sheet variables to the following:
    Please Login or Register  to view this content.
    I am stiling getting the subcript our of range error

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: application.activewindow issue

    If the error occurs there, then the sheet name is wrong.
    Also, you are assigning both sheets to the same variable...

  9. #9
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: application.activewindow issue

    hI

    Had not relasied i had misspelt the second sheet variable...thanks for pinting that out

    I have checked the sheet names and theya re correct but i am still getting the subscript out of range error

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: application.activewindow issue

    If the error occurs on one of those two lines (and it would be helpful to know which one) then:
    EITHER the sheet name is incorrect;
    OR the wrong workbook is active when you run the code.

  11. #11
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: application.activewindow issue

    When the code is running their are two workbooks open, one which holds the macro and another which the macro should be looking in.

    It errors on this line
    Please Login or Register  to view this content.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: application.activewindow issue

    That doesn't change my answer.

  13. #13
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: application.activewindow issue

    Well i have checked the sheets names and thye are correct, however how do you get it to look at correct activeworkbook

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: application.activewindow issue

    The active workbook is whichever workbook is active (i.e. visible in the Excel window) when you run the code. If it should always refer to a specific workbook, refer to the workbook name instead of assuming it's the active one.

  15. #15
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: application.activewindow issue

    Ok i'll try that

    thank you very much for your help you have been a great help Thanks!

+ 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