+ Reply to Thread
Results 1 to 6 of 6

Macro Error when File Name Changes

  1. #1
    Registered User
    Join Date
    07-17-2008
    Location
    NY
    Posts
    9

    Macro Error when File Name Changes

    I recently recorded a Macro on Excel and then did a Save As, changing the name of the file.

    When I opened this new file, however, there was an error and the Macros did not work.

    Run Time error '1004':
    "Liquidity Sheet.xls" could not be found. Check the spelling of the name.....

    Basically the macro is programmed to work with the old workbook filename.

    Why doesn't this change automatically when I do a Save As?

    How can I get around this issue? I'm concerned other people using the spreadsheet will change its name.

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    VBA does not automatically update workbook names. Can you post the entire code, and tell us what exactly you want the macro to do?

  3. #3
    Registered User
    Join Date
    07-17-2008
    Location
    NY
    Posts
    9
    Its a very simple macro that sorts rows based on the values in a few hidden columns by clicking a button.

    Is there anyway to save macros to use across multiple workbooks?

    Here is the code on one of the buttons:
    Sub FilterAll()
    '
    ' FilterAll Macro
    ' Macro recorded 7/17/2008 by Antarctica-COMP2
    '

    '
    Selection.AutoFilter Field:=1
    Selection.AutoFilter Field:=2
    Selection.AutoFilter Field:=3
    End Sub
    Sub FilterAMNF()
    '
    ' FilterAMNF Macro
    ' Macro recorded 7/17/2008 by Antarctica-COMP2
    '

    '
    Application.Run _
    "'Copy of Liquidity Leverage client base risks (2).xls'!FilterAll"
    Selection.AutoFilter Field:=1, Criteria1:="AMNF"
    End Sub
    Sub FilterAGEF()
    '
    ' FilterAGEF Macro
    ' Macro recorded 7/17/2008 by Antarctica-COMP2
    '

    '
    Application.Run _
    "'Copy of Liquidity Leverage client base risks (2).xls'!FilterAll"
    Selection.AutoFilter Field:=3, Criteria1:="aGEF"
    End Sub
    Sub FilterAGOF()
    '
    ' FilterAGOF Macro
    ' Macro recorded 7/17/2008 by Antarctica-COMP2
    '

    '
    Application.Run _
    "'Copy of Liquidity Leverage client base risks (2).xls'!FilterAll"
    Selection.AutoFilter Field:=2, Criteria1:="AGOF"
    End Sub
    Sub ALL()
    '
    ' ALL Macro
    ' Macro recorded 7/17/2008 by Antarctica-COMP2
    '

    '
    Selection.AutoFilter Field:=1
    Selection.AutoFilter Field:=2
    Selection.AutoFilter Field:=3
    End Sub
    Sub AMNF()
    '
    ' AMNF Macro
    ' Macro recorded 7/17/2008 by Antarctica-COMP2
    '

    '
    Selection.AutoFilter Field:=1
    Application.Run "'Liq Lev Client Risk Macro Test Sheet.xls'!ALL"
    Selection.AutoFilter Field:=1, Criteria1:="AMNF"
    End Sub
    Sub AGOF()
    '
    ' AGOF Macro
    ' Macro recorded 7/17/2008 by Antarctica-COMP2
    '

    '
    Application.Run "'Liq Lev Client Risk Macro Test Sheet.xls'!ALL"
    Selection.AutoFilter Field:=2, Criteria1:="AGOF"
    End Sub
    Sub AGEF()
    '
    ' AGEF Macro
    ' Macro recorded 7/17/2008 by Antarctica-COMP2
    '

    '
    Application.Run "'Liq Lev Client Risk Macro Test Sheet.xls'!ALL"
    Selection.AutoFilter Field:=3, Criteria1:="aGEF"
    End Sub

  4. #4
    Registered User
    Join Date
    07-17-2008
    Location
    NY
    Posts
    9
    Sorry...to clarify...

    All the macro does is filters data so I can hide the columns which are being filtered.

    I will attach the sheet.
    Attached Files Attached Files

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    Is it in the same workbook? If so, FilterAll should work by itself. Otherwise, use string concatenation to build a workbook's name.

  6. #6
    Registered User
    Join Date
    08-10-2007
    Posts
    51
    I'm not sure if this is going to help you because I don't see liquidity sheet referenced anywhere.

    Here is the quick and dirty way to finish what you want to get done:

    Before that, do you know the positions of your sheets? If your Liquidity.xls sheet is in the first position, then just replace

    Application.Run "'Liq Lev Client Risk Macro Test Sheet.xls'!ALL" WITH

    Dim sheet_name as string
    sheet_name = sheets(1) 'Sets the first sheet name

    Application.Run sheets(1) & "'!ALL""

+ 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