Macro causes Excel to stop Responding

AK30

New Member
Joined
Aug 28, 2011
Messages
2
Hola - due to company security can't post from the computer I'm actually working on this so here is the snip of code Excel is hanging up on:

newfn = Application.GetOpenFilename(FileFilter:="Scrub File (*.xls), *.xls", Title:="Please select yesterday's results scrub file")
If newfn = False Then
MsgBox "Process cannot continue without selection of a scrub file"
Exit Sub
Else
Set srcwrkbk = Workbooks.Open(newfn)
srcwrkbk.Activate
Columns("A:R").Copy
ThisWorkbook.Activate
Sheets("ScrubSheet").Paste Destination:=Range("A1")
srcwrkbk.Close True
End If

I commented out these lines:
'Columns("A:R").Copy
'ThisWorkbook.Activate
'Sheets("ScrubSheet").Paste Destination:=Range("A1")
and it works (sans copy / paste) but when they are added back in Excel just locks up. Thoughts?

(Using Excel 2003)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this:
Code:
Option Explicit

Sub TestMacro()
Dim newFN As String
Dim srcWB As Workbook
Dim destWS As Worksheet

newFN = Application.GetOpenFilename(FileFilter:="Scrub File (*.xls), *.xls", Title:="Please select yesterday's results scrub file")
If newFN = False Then
    MsgBox "Process cannot continue without selection of a scrub file"
    Exit Sub
End If

Set destWS = ThisWorkbook.Sheets("ScrubSheet")
Set srcWB = Workbooks.Open(newFN)
Activatesheet.Range("A:R").Copy destWS.Range("A1")
srcWB.Close True

End Sub
 
Upvote 0
Thanks for the reply jbeaucaire. For some reason that gave me a Type Mismatch error on the "If newFN = False Then" line. I've got it working now though with this:


newFN = Application.GetOpenFilename(FileFilter:="Scrub File (*.xls), *.xls", Title:="Please select yesterday's results scrub file")
If newFN = False Then MsgBox "Process cannot continue without selection of a scrub file"
Exit Sub
End If

Set destWS = ThisWorkbook.Sheets("ScrubSheet")
Set srcWB = Workbooks.Open(newFN)
srcWB.Sheets("Distribution").Range("A:R").Copy destWS.Range("A1")
srcWB.Close True


Thanks again!
 
Upvote 0
Sorry, my bad, it was supposed to be "False", not False.
Code:
Option Explicit

Sub TestMacro()
Dim newFN As String
Dim srcWB As Workbook
Dim destWS As Worksheet

newFN = Application.GetOpenFilename(FileFilter:="Scrub File (*.xls), *.xls", Title:="Please select yesterday's results scrub file")
If newFN = "False" Then
    MsgBox "Process cannot continue without selection of a scrub file"
    Exit Sub
End If

Set destWS = ThisWorkbook.Sheets("ScrubSheet")
Set srcWB = Workbooks.Open(newFN)
Activatesheet.Range("A:R").Copy destWS.Range("A1")
srcWB.Close True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top