LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro runs within VBE, but does not run to completion via a ho

Personally, I only have a couple of macros that use shortcut keys--and they
don't open other files.

I'd use a button on a worksheet or a floating toolbar (xl2003 or earlier) or
modify the ribbon/QAT in xl2007 to start macros.

MichaelDavid wrote:

Hi Dave:

From the Microsoft Knowledge Base:

"The workaround for this problem (only applicable on Windows ® platforms) is
to detect whether the shift key is pressed and wait for it to be released
before issuing the Workbooks.Open command:

'Declare API
Declare Function GetKeyState Lib "User32" _
(ByVal vKey As Integer) As Integer
Const SHIFT_KEY = 16

Function ShiftPressed() As Boolean
'Returns True if shift key is pressed
ShiftPressed = GetKeyState(SHIFT_KEY) < 0
End Function

Sub Demo()
Do While ShiftPressed()
DoEvents
Loop
Workbooks.Open ="C:\My Documents\ShiftKeyDemo.xls"
End Sub
"
(My workaround: Examine all macros for the ones that open files. Remove
Shift from their HotKeys. I found quite a few. Only probem: I have nearly run
out of possible HotKeys. What might be a solution or workaround for that
problem?)
--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick

"Dave Peterson" wrote:

Remove the shift key from the shortcut key combination and try it again.



MichaelDavid wrote:

Greetings! The below macro runs perfectly from within the VBE
Editor(RunSub/UserForm), but when run via a hotkey (Ctrl+Shift+K), Excel
gives up after executing the following instruction:
Workbooks.Open FileName:=DataFileToOpen .
That file opens properly but Excel does not execute the rest of the
instructions in the macro. The program doesn't hang, and there are no error
messages.

Sub TestFileOpen()

' Hotkey Ctrl+Shift+K

' Note: ActiveSheet.Name is 19TwinButte
' Note: DataFileToOpen is
"C:\InsiderIndustryResults\BookIssuers19TwinButte. xlsm"
' and it exists.

Dim CurrentActiveSheet As String
Dim DataFileToOpen As String

CurrentActiveSheet = ActiveSheet.Name

' The sheet name is used in forming the file name. Thus the sheet name is
19TwinButte, and the file name is "BookIssuers19TwinButte.xlsm" .
19TwinButte is the name of one of the worksheets in file
"BookIssuers19TwinButte.xlsm"

If Dir("C:\InsiderIndustryResults\BookIssuers" & CurrentActiveSheet &
".xlsm") < "" Then
DataFileToOpen = "C:\InsiderIndustryResults\BookIssuers" &
CurrentActiveSheet & ".xlsm"
MsgBox "DataFileToOpen is " & DataFileToOpen
Workbooks.Open FileName:=DataFileToOpen
Workbooks("BookIssuers" & CurrentActiveSheet & ".xlsm").
Worksheets(CurrentActiveSheet).Activate
' Copy data from that workbook into active workbook:
Workbooks("BookIssuers" & CurrentActiveSheet &
".xlsm").Worksheets(CurrentActiveSheet).Range("AJ7 :AU140").Copy
Workbooks("BookIssuers.xlsm").Worksheets(CurrentAc tiveSheet).Range("AJ7")

' Now close that workbook:
ActiveWorkbook.Close
End If

End Sub

I will greatly appreciate any suggestions or workarounds.
--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick


--

Dave Peterson
.


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA macro runs fine, but freezes if I try to do ANYTHING else whileit runs Rruffpaw Setting up and Configuration of Excel 1 September 17th 11 01:25 PM
Macro - Setence Completion TGalin Excel Programming 2 February 22nd 09 04:14 PM
Global macro hotkey Mikus Excel Programming 1 August 17th 05 08:54 PM
Unable to get macro hotkey to work Relvinian Excel Programming 1 August 24th 04 04:45 PM
Having a status bar (%completion) displayed while my macro runs I CAN FLY[_2_] Excel Programming 2 June 3rd 04 03:29 PM


All times are GMT +1. The time now is 05:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"