Consulting

Results 1 to 5 of 5

Thread: Short cut keys won't run entire macro

  1. #1
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    4
    Location

    Short cut keys won't run entire macro

    Hello forum,
    I'm trying to write a program to transfer data from several workbooks to one workbook. It seems to work perfect when I run the program from the VBA editor. However, as soon as I use a short cut key to run the program, it cuts out. Particulary, it stops immediately after the workbooks.open function. Anyone know what the problem is? Is there a way to fix this?
    Thanks!
    yeb4444

    MsgBox() is never reached:

    Workbooks.Open Filename:=Location_Files & Industry_Name & Update_Name_End
    MsgBox (Check)

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sounds like you have an unhandled error.

    Show all the code.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    4
    Location
    Quote Originally Posted by xld
    Sounds like you have an unhandled error.

    Show all the code.

    I'm afraid it is a fair amount of code, but here goes. It takes in the File Location, Save Location, update identifier and Industry Name from the excel work book. The right and left functions cut out quotation marks. Any ideas? The part that really confuses me is that it works if run from the editor.
    Thanks!
    David



    Sub Make_Master_Main()
    '
    ' This macro makes master data sheets for each industry listed on the input sheet.
    ' Make_Master_Main() 1) inputs the industry name from the input sheet and 2) runs Make_Master_RunAllFunctions() for that industry

    ' Application.ScreenUpdating = False 'turns off screen updating. Makes the Application run much faster
    ' Application.StatusBar = "Processing All Workbooks..."
    '
    Workbooks("Make Masters.xls").Activate 'activate the workbook associated with this macro
    Sheets("Input Sheet").Activate 'activate the input sheet

    Set FinalIndustryCell = Range("C65536").End(xlUp) 'Get the location of the bottom of the industries list

    For Each Industry In Range("C10", FinalIndustryCell) 'For all cells in the industry list
    Industry_Name = Right(Left(Industry.Value, Len(Industry.Value) - 1), Len(Industry.Value) - 2) 'imput and remove parentheses
    Make_Master_RunAllFunctions (Industry_Name) 'Run all functions for that industry
    Next

    Application.ScreenUpdating = True 'turn screen updating back on
    Application.StatusBar = False 'return the status bar to normal state

    End Sub

    Sub Make_Master_RunAllFunctions(Industry_Name)
    '
    '
    '

    Workbooks.Add ' Create a new workbook (the master workbook)
    Set WS_Main = ActiveWorkbook ' Sets new workbook to WS_Main
    WS_Main.Sheets.Add Count:=13 ' Adds 13 sheets to the new workbook for a total of 16 sheets
    MasterFinalRow = 2 ' Sets FinalRow variable to 2 (because the first two rows are preset header rows)
    Workbooks("Make Masters.xls").Activate 'Activate the Make Masters workbooks
    Range("A65536").End(xlUp).Select
    FinalRow = ActiveCell.Row

    Location_Files = Right(Left(Cells(4, 1).Value, Len(Cells(4, 1).Value) - 1), Len(Cells(4, 1).Value) - 2)
    MySaveAs_File = Right(Left(Cells(7, 1).Value, Len(Cells(7, 1).Value) - 1), Len(Cells(7, 1).Value) - 2) & Industry_Name & " Master.xls"
    Update_Name_End = Cells(10, 1).Value
    Update_Name_End = Right(Left(Update_Name_End, Len(Update_Name_End) - 1), Len(Update_Name_End) - 2)

    Workbooks.Open Filename:=Location_Files & Industry_Name & Update_Name_End
    MsgBox (Check)
    ...

  4. #4
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    4
    Location
    [VBA]Sub Make_Master_Main()
    '
    ' This macro makes master data sheets for each industry listed on the input sheet.
    ' Make_Master_Main() 1) inputs the industry name from the input sheet and 2) runs Make_Master_RunAllFunctions() for that industry

    ' Application.ScreenUpdating = False 'turns off screen updating. Makes the Application run much faster
    ' Application.StatusBar = "Processing All Workbooks..."
    '
    Workbooks("Make Masters.xls").Activate 'activate the workbook associated with this macro
    Sheets("Input Sheet").Activate 'activate the input sheet

    Set FinalIndustryCell = Range("C65536").End(xlUp) 'Get the location of the bottom of the industries list

    For Each Industry In Range("C10", FinalIndustryCell) 'For all cells in the industry list
    Industry_Name = Right(Left(Industry.Value, Len(Industry.Value) - 1), Len(Industry.Value) - 2) 'imput and remove parentheses
    Make_Master_RunAllFunctions (Industry_Name) 'Run all functions for that industry
    Next

    Application.ScreenUpdating = True 'turn screen updating back on
    Application.StatusBar = False 'return the status bar to normal state

    End Sub

    Sub Make_Master_RunAllFunctions(Industry_Name)
    '
    '
    '

    Workbooks.Add ' Create a new workbook (the master workbook)
    Set WS_Main = ActiveWorkbook ' Sets new workbook to WS_Main
    WS_Main.Sheets.Add Count:=13 ' Adds 13 sheets to the new workbook for a total of 16 sheets
    MasterFinalRow = 2 ' Sets FinalRow variable to 2 (because the first two rows are preset header rows)
    Workbooks("Make Masters.xls").Activate 'Activate the Make Masters workbooks
    Range("A65536").End(xlUp).Select
    FinalRow = ActiveCell.Row

    Location_Files = Right(Left(Cells(4, 1).Value, Len(Cells(4, 1).Value) - 1), Len(Cells(4, 1).Value) - 2)
    MySaveAs_File = Right(Left(Cells(7, 1).Value, Len(Cells(7, 1).Value) - 1), Len(Cells(7, 1).Value) - 2) & Industry_Name & " Master.xls"
    Update_Name_End = Cells(10, 1).Value
    Update_Name_End = Right(Left(Update_Name_End, Len(Update_Name_End) - 1), Len(Update_Name_End) - 2)

    Workbooks.Open Filename:=Location_Files & Industry_Name & Update_Name_End
    MsgBox (Check)
    [/VBA]

  5. #5
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    4
    Location
    got the problem - it appears to be with the hotkey I selected.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •