HotNumbers
Well-known Member
- Joined
- Feb 14, 2005
- Messages
- 732
Can someone please Help me modify a code. I am able to import the sheet that i need, once imported to the open Workbook I need the workbook imported from to close.
Below is my code.
Sub Load_External()
ANS = MsgBox("Import Ledge data from an external workbook source?", vbYesNo + vbQuestion, "Import Ledger Data")
If ANS = vbNo Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
'Remove #REF Name Range
Sheets("LEDGER PREP SHEET").Select
Dim nName As Name
For Each nName In Names
If InStr(1, nName.RefersTo, "#REF!") > 0 Then
nName.Delete
End If
Next nName
On Error GoTo Error_Loader
Load:
NAME1 = Application.GetOpenFilename
Set NAME2 = ThisWorkbook
If NAME1 = False Then
ANS = MsgBox("The load process has been canceled. " & vbNewLine & vbNewLine & _
"Click RETRY to restart the load process " & vbNewLine & _
"Click CANCEL to end the load process", vbRetryCancel, _
"Bento Box")
If ANS = vbRetry Then GoTo Load
If ANS = vbCancel Then Exit Sub
End If
Sheets("LEDGER PREP SHEET").Visible = True
Sheets("LEDGER PREP SHEET").Select
Cells.Clear
Range("a1").Select
Workbooks.Open Filename:=NAME1
Set NAME3 = ActiveWorkbook
NM = ActiveWorkbook.Name
Sheets("Ledger Inquiry").Select
Cells.Copy
NAME2.Activate
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Beep
MsgBox "Data successfully imported"
Range("a1").Select
Exit Sub
Error_Loader:
MsgBox "Import error"
NAME2.Activate
Sheets("LEDGER PREP SHEET").Visible = False
End Sub
Below is my code.
Sub Load_External()
ANS = MsgBox("Import Ledge data from an external workbook source?", vbYesNo + vbQuestion, "Import Ledger Data")
If ANS = vbNo Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
'Remove #REF Name Range
Sheets("LEDGER PREP SHEET").Select
Dim nName As Name
For Each nName In Names
If InStr(1, nName.RefersTo, "#REF!") > 0 Then
nName.Delete
End If
Next nName
On Error GoTo Error_Loader
Load:
NAME1 = Application.GetOpenFilename
Set NAME2 = ThisWorkbook
If NAME1 = False Then
ANS = MsgBox("The load process has been canceled. " & vbNewLine & vbNewLine & _
"Click RETRY to restart the load process " & vbNewLine & _
"Click CANCEL to end the load process", vbRetryCancel, _
"Bento Box")
If ANS = vbRetry Then GoTo Load
If ANS = vbCancel Then Exit Sub
End If
Sheets("LEDGER PREP SHEET").Visible = True
Sheets("LEDGER PREP SHEET").Select
Cells.Clear
Range("a1").Select
Workbooks.Open Filename:=NAME1
Set NAME3 = ActiveWorkbook
NM = ActiveWorkbook.Name
Sheets("Ledger Inquiry").Select
Cells.Copy
NAME2.Activate
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Beep
MsgBox "Data successfully imported"
Range("a1").Select
Exit Sub
Error_Loader:
MsgBox "Import error"
NAME2.Activate
Sheets("LEDGER PREP SHEET").Visible = False
End Sub