+ Reply to Thread
Results 1 to 10 of 10

Vba code working in workbook module but not working from personal.xlb

  1. #1
    Forum Contributor satputenandkumar0's Avatar
    Join Date
    11-08-2012
    Location
    Pune, India
    MS-Off Ver
    Office xp & Office 2007
    Posts
    398

    Question Vba code working in workbook module but not working from personal.xlb

    Dear Members,

    Below VBA code copies certain columns in to active workbook from file after selecting . Code works perfect there (In workbook module). If I kept this code in personal.xlb, It is giving Run-time error'9':Subscript out of range see red line where error comes.

    Please Login or Register  to view this content.
    Regards,
    Nandkumar S.
    ---------------------------------------------------------------
    Don't forget to Click on * if you like my solution.

  2. #2
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Vba code working in workbook module but not working from personal.xlb

    ThisWorkbook refers to the workbook the macro is in i.e. the personal workbook.

    Try using ActiveWorkbook.
    Last edited by WasWodge; 04-18-2014 at 09:52 AM. Reason: dodgy capitalization with phone
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  3. #3
    Forum Contributor satputenandkumar0's Avatar
    Join Date
    11-08-2012
    Location
    Pune, India
    MS-Off Ver
    Office xp & Office 2007
    Posts
    398

    Re: Vba code working in workbook module but not working from personal.xlb

    Dear WasWodge,

    Thanks for reply.

    same error after changing

  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Vba code working in workbook module but not working from personal.xlb

    Then try referring to the actual workbook name or wbSource.
    Last edited by WasWodge; 04-18-2014 at 10:10 AM.

  5. #5
    Forum Contributor satputenandkumar0's Avatar
    Join Date
    11-08-2012
    Location
    Pune, India
    MS-Off Ver
    Office xp & Office 2007
    Posts
    398

    Re: Vba code working in workbook module but not working from personal.xlb

    sir,

    I use this code for many workbooks.

  6. #6
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Vba code working in workbook module but not working from personal.xlb

    See the edit = wbSource

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Do you need the line causing the error?
    If posting code please use code tags, see here.

  8. #8
    Forum Contributor satputenandkumar0's Avatar
    Join Date
    11-08-2012
    Location
    Pune, India
    MS-Off Ver
    Office xp & Office 2007
    Posts
    398

    Re: Vba code working in workbook module but not working from personal.xlb

    Yes sir,

    I want line for activate current workbook

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Vba code working in workbook module but not working from personal.xlb

    I believe this is correct. Note, when developing a macro that will reside in your Personal file, ALL commands referencing sheet ranges must be attached to a parent sheet object to properly target the command. The best way to do this is to declare worksheet and workbook reference at the beginning of the macro for all objects you will address, that includes the both the SOURCE objects and the DESTINATION targets.

    Towards the end of your macro you are calling another macro. I believe that macro should be amended to accept an object reference fed into from this macro so the other macro has the address of the object HTC already as well.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  10. #10
    Forum Contributor satputenandkumar0's Avatar
    Join Date
    11-08-2012
    Location
    Pune, India
    MS-Off Ver
    Office xp & Office 2007
    Posts
    398

    Re: Vba code working in workbook module but not working from personal.xlb

    Dear JBeaucaire,

    sorry for late reply. I was out of town.

    Your solution works perfect. And very thanks for your valuable guidance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Import module then run code not working.
    By R-Enemy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2015, 06:08 PM
  2. [SOLVED] Working with WorkBook Close event and Personal.xlsb files
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2013, 12:40 AM
  3. Code to Copy a Module from on Workbook to another not working?
    By JungleJme in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2013, 10:48 AM
  4. [SOLVED] VBA code stops working when I lock the workbook for use
    By Sleepyshy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2013, 02:55 PM
  5. same code not working in different workbook
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-20-2008, 04:29 AM

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