+ Reply to Thread
Results 1 to 2 of 2

Can a Macro use Different File Names?

  1. #1
    markmidwest
    Guest

    Can a Macro use Different File Names?

    I am trying to create a macro that goes across 2 spreadsheets, the name of
    the first spreadsheet will remane consistent but the second spreadsheet will
    have a randomly generated name. I created a macro that runs the functions
    that I need but only if the second spreadsheet name doesn't change, once it
    changes I get errors.

    Is there a way to create a macro like this?

    Thank you in advance for your help.

    -Mark

  2. #2
    Tom Ogilvy
    Guest

    RE: Can a Macro use Different File Names?


    Assume there are only two visible workbooks (spreadsheets)
    Dim bk as Workbook, bk1 as Workbook, bk2 as Workbook
    for each bk in Workbooks
    if bk.Windows(1).Visible then
    if lcase(bk.name) <> "constant.xls" then
    sName = bk.name
    exit sub
    end if
    end if
    Next

    set bk2 = workbooks(sname)
    set bk1 = workbooks("constant.xls")

    Obviously change constant.xls to the name (in lowercase) of the fixed name
    workbook

    If you meant sheets in the same workbook, then just use worksheet/worksheets
    instead of workbook/workbooks

    --
    Regards,
    Tom Ogilvy
    "markmidwest" wrote:

    > I am trying to create a macro that goes across 2 spreadsheets, the name of
    > the first spreadsheet will remane consistent but the second spreadsheet will
    > have a randomly generated name. I created a macro that runs the functions
    > that I need but only if the second spreadsheet name doesn't change, once it
    > changes I get errors.
    >
    > Is there a way to create a macro like this?
    >
    > Thank you in advance for your help.
    >
    > -Mark


+ 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