Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro works from RUN but not from shortcut
I have a macro which opens an workbook and then transfers
date from the just opened book into the book which has the macro. The macro will then close the external workbook. This is using Excel 2002 with Windoes ME. This macro runs fine when single stepping through it and it works fine when selecting it and then hitting "RUN" from the Tools-Macro-Macros menu but when using a shortcut key, the macro will start to run normally but then it will not execute the statements directly above the section with the close in it. I tried a couple of different shortcut key combos just in case it was a conflict in the shortcuts but no change. I have tried running the macro by "Call"ing it from another macro and I have tried inserting a for-next loop in a couple of places simply to use some time in case it is not getting a chance to comple the preceeding steps but still it will not operate correctly when using the shortcut. The code which opens the file and some of the following code is: Windows("Even-WeeklyMasters.xls").Activate Sheets("Master").Select varYear = InputBox("Enter full name, NOT including .xls, of the file being used to create the updated master sheets.") varYear2 = "C:\ECTL\" & varYear varyear1 = varYear & ".xls" Workbooks.Open (varYear2) Sheets("WeeklySheetsOdd").Select Range("shootdates").Select Selection.Copy Windows("Even-WeeklyMasters.xls").Activate Range("bg1").Activate Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False 'Application.ScreenUpdating = False 'Sheets("Master").Select Range("A1").Select Windows("Even-WeeklyMasters.xls").Activate Range("master_clear").ClearContents Range("master_clear").ClearComments Range("master_clear").Interior.ColorIndex = xlNone 'Selection. Range("a1").Activate Windows(varyear1).Activate Range("names_al_1").Copy Windows("Even-WeeklyMasters.xls").Activate Range("m_al_names_1").Activate Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False The code used which seems not to execute when run from the shortcut, but which does run fine when using the Run button, (code which does not run marked with *) is: Windows(varyear1).Activate Range("names_sp_1").Copy Windows("even-weeklymasters.xls").Activate Range("m_sp_names_1").Activate Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False * Windows("Even-WeeklyMasters.xls").Activate Sheets("Master").Select * MsgBox ("The workbook being used to supply names, ") & varyear1 & (" will now be closed.") Workbooks(varyear1).Close SaveChanges:=False The Msgbox line and the line above it will NOT execute when run from the shortcut but does appear when the macro is strated from the Run button or when single stepping. HELP!!!! Why will it not run properly from the Shortcut???? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro works from RUN but not from shortcut
Your shortcut key has includes the shift key?
If yes, use a different shortcut key (w/o the shift key). (When you open a file while holding the shift key, you disable the auto_open/workbook_open macros. Excel gets confused and thinks it should stop running macros when you do this with the shortcut key, too.) Joe Pyrdek wrote: I have a macro which opens an workbook and then transfers date from the just opened book into the book which has the macro. The macro will then close the external workbook. This is using Excel 2002 with Windoes ME. This macro runs fine when single stepping through it and it works fine when selecting it and then hitting "RUN" from the Tools-Macro-Macros menu but when using a shortcut key, the macro will start to run normally but then it will not execute the statements directly above the section with the close in it. I tried a couple of different shortcut key combos just in case it was a conflict in the shortcuts but no change. I have tried running the macro by "Call"ing it from another macro and I have tried inserting a for-next loop in a couple of places simply to use some time in case it is not getting a chance to comple the preceeding steps but still it will not operate correctly when using the shortcut. The code which opens the file and some of the following code is: Windows("Even-WeeklyMasters.xls").Activate Sheets("Master").Select varYear = InputBox("Enter full name, NOT including .xls, of the file being used to create the updated master sheets.") varYear2 = "C:\ECTL\" & varYear varyear1 = varYear & ".xls" Workbooks.Open (varYear2) Sheets("WeeklySheetsOdd").Select Range("shootdates").Select Selection.Copy Windows("Even-WeeklyMasters.xls").Activate Range("bg1").Activate Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False 'Application.ScreenUpdating = False 'Sheets("Master").Select Range("A1").Select Windows("Even-WeeklyMasters.xls").Activate Range("master_clear").ClearContents Range("master_clear").ClearComments Range("master_clear").Interior.ColorIndex = xlNone 'Selection. Range("a1").Activate Windows(varyear1).Activate Range("names_al_1").Copy Windows("Even-WeeklyMasters.xls").Activate Range("m_al_names_1").Activate Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False The code used which seems not to execute when run from the shortcut, but which does run fine when using the Run button, (code which does not run marked with *) is: Windows(varyear1).Activate Range("names_sp_1").Copy Windows("even-weeklymasters.xls").Activate Range("m_sp_names_1").Activate Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False * Windows("Even-WeeklyMasters.xls").Activate Sheets("Master").Select * MsgBox ("The workbook being used to supply names, ") & varyear1 & (" will now be closed.") Workbooks(varyear1).Close SaveChanges:=False The Msgbox line and the line above it will NOT execute when run from the shortcut but does appear when the macro is strated from the Run button or when single stepping. HELP!!!! Why will it not run properly from the Shortcut???? -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro works Macro does not work | Excel Discussion (Misc queries) | |||
Insert Hyperlink shortcut no longer works | Links and Linking in Excel | |||
Insert Hyperlink shortcut no longer works | Links and Linking in Excel | |||
macro works in .xlt but not .xls | Excel Programming | |||
A good macro that works wrong with keyboard shortcut | Excel Programming |