C
chillihawk
Hello Everyone,
I have a Sub in an add-in which when called (via a keyboard shortcut
CTRL+SHIFT+G) opens an existing workbook, gets some data out of it and
puts that data on the sheet. The function is driven by data in the
comment of the Activecell. Now it works when I step through it, it
works when I run through it (ie hit F5), (presuming in both cases the
activecell is the correct one) but it will not execute properly in
response to the keyboard shortcut. It stops after opening the existing
workbook. Here is the offending code:
For k = 1 To UBound(s, 1)
Set wbk = Application.Workbooks.Open(fileName:=s(k), AddtoMru:=False,
IgnoreReadOnlyRecommended:=True)
If (wbk Is Nothing) Then Err.Raise vbError + 2001, FUNCTION_NAME,
"Unable to open correlation source."
i = j
With wbk
..IsAddin = True
While (vToGet(i, 3) = s(k))
vToGet(i, 6) = wbk.Sheets("grid").Range(oMyTx.getAsXLColumn(vToGet(i,
5) + 2) & CStr(vToGet(i, 4))).Value
i = i + 1
Wend
subscriptStart:
j = i - 1
End With
wbk.Close SaveChanges:=False
Set wbk = Nothing
Next k
wbk is declared: Dim wbk as Workbook
I don't know if a reference to wbk is ever set, it seems like it isn't
but I can't tell why. When execution stops, the workbook (ie s(k) in
the above code) is open and active and when I press ALT + F11 to go
into the debugger it is sometimes in design mode and sometimes not.
Can anyone shed any light on this problem.
Thanks everyone,
chilli
I have a Sub in an add-in which when called (via a keyboard shortcut
CTRL+SHIFT+G) opens an existing workbook, gets some data out of it and
puts that data on the sheet. The function is driven by data in the
comment of the Activecell. Now it works when I step through it, it
works when I run through it (ie hit F5), (presuming in both cases the
activecell is the correct one) but it will not execute properly in
response to the keyboard shortcut. It stops after opening the existing
workbook. Here is the offending code:
For k = 1 To UBound(s, 1)
Set wbk = Application.Workbooks.Open(fileName:=s(k), AddtoMru:=False,
IgnoreReadOnlyRecommended:=True)
If (wbk Is Nothing) Then Err.Raise vbError + 2001, FUNCTION_NAME,
"Unable to open correlation source."
i = j
With wbk
..IsAddin = True
While (vToGet(i, 3) = s(k))
vToGet(i, 6) = wbk.Sheets("grid").Range(oMyTx.getAsXLColumn(vToGet(i,
5) + 2) & CStr(vToGet(i, 4))).Value
i = i + 1
Wend
subscriptStart:
j = i - 1
End With
wbk.Close SaveChanges:=False
Set wbk = Nothing
Next k
wbk is declared: Dim wbk as Workbook
I don't know if a reference to wbk is ever set, it seems like it isn't
but I can't tell why. When execution stops, the workbook (ie s(k) in
the above code) is open and active and when I press ALT + F11 to go
into the debugger it is sometimes in design mode and sometimes not.
Can anyone shed any light on this problem.
Thanks everyone,
chilli