+ Reply to Thread
Results 1 to 4 of 4

Problem with Macro working in new workbooks that I open

  1. #1
    chris_rip
    Guest

    Problem with Macro working in new workbooks that I open

    I created a Macro just using the record Macro tool. I'm analyzing data
    points by graphing 600 points and also finding a slope and R-squared value of
    these points. When I open excel, import the data, and run the Macro
    everything works fine. However, when I save that file and open a new book
    the Macro encounters a bug. I open visual basic and change the line that is
    a problem from the Book1 to Book2 and click Run and the Macro works fine.
    Does anyone know a way to change this to avoid this nuisance? Thanks for all
    your help.

  2. #2
    Bob Phillips
    Guest

    Re: Problem with Macro working in new workbooks that I open

    Use Activeworkbook instead of Workbooks("Book1.xls")

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "chris_rip" <[email protected]> wrote in message
    news:[email protected]...
    > I created a Macro just using the record Macro tool. I'm analyzing data
    > points by graphing 600 points and also finding a slope and R-squared value

    of
    > these points. When I open excel, import the data, and run the Macro
    > everything works fine. However, when I save that file and open a new book
    > the Macro encounters a bug. I open visual basic and change the line that

    is
    > a problem from the Book1 to Book2 and click Run and the Macro works fine.
    > Does anyone know a way to change this to avoid this nuisance? Thanks for

    all
    > your help.




  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Chris,

    Just change the code references form "Book1" to "ActiveWorkbook" or "ThisWorkbook". Now when the code is copied it is independent of the Workbook's name.

    Sincerely,
    Leith Ross

  4. #4
    chris_rip
    Guest

    Re: Problem with Macro working in new workbooks that I open

    That seemed to do the trick. I'm glad to know that it was something so
    simple to fix the problem. Thanks for the tip.

    CR


    "Bob Phillips" wrote:

    > Use Activeworkbook instead of Workbooks("Book1.xls")
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "chris_rip" <[email protected]> wrote in message
    > news:[email protected]...
    > > I created a Macro just using the record Macro tool. I'm analyzing data
    > > points by graphing 600 points and also finding a slope and R-squared value

    > of
    > > these points. When I open excel, import the data, and run the Macro
    > > everything works fine. However, when I save that file and open a new book
    > > the Macro encounters a bug. I open visual basic and change the line that

    > is
    > > a problem from the Book1 to Book2 and click Run and the Macro works fine.
    > > Does anyone know a way to change this to avoid this nuisance? Thanks for

    > all
    > > your help.

    >
    >
    >


+ 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