As per title...
What I am trying to do is copy a worksheet from another file.
I've stripped all of the variable declarations and all other non-relevant code in the example below, just know that it does work via the button click event.
When I run the code via pressing the Macro shortcut, the file opens successfully but the code just stops running. No errors. No nothing.
I put a breakpoint where it actually performs the copy, but it never gets there?
That pathetic looking DoEvents was very hopeful, thinking that maybe the file opened too slowly...
Curiously... running the macro directly from the Macros panel, I get a "Run-time error '9': Subscript out of range" error where I try to close Window(file).Close. The file appeared to have automatically been closed?! Commenting out that line and the code ran as it should...
Any help would be very much appreciated.
Thanks.
What I am trying to do is copy a worksheet from another file.
I've stripped all of the variable declarations and all other non-relevant code in the example below, just know that it does work via the button click event.
When I run the code via pressing the Macro shortcut, the file opens successfully but the code just stops running. No errors. No nothing.
I put a breakpoint where it actually performs the copy, but it never gets there?
That pathetic looking DoEvents was very hopeful, thinking that maybe the file opened too slowly...
Curiously... running the macro directly from the Macros panel, I get a "Run-time error '9': Subscript out of range" error where I try to close Window(file).Close. The file appeared to have automatically been closed?! Commenting out that line and the code ran as it should...
Code:
Option Explicit
Private Sub btnQuotes_Refresh_Click()
Call Quotes_Refresh
End Sub
Public Sub Quotes_Refresh()
'
' Keyboard Shortcut: Ctrl+Shift+U
'
Workbooks.Open ("" & QUOTES_DIRECTORY & file & "")
DoEvents
Sheets(ws).Move After:=Workbooks("SE.xlsm").Sheets(position)
Windows(file).Close
End Sub
Any help would be very much appreciated.
Thanks.