Runtime Error 438

scottiedawg4

New Member
Joined
Jul 25, 2011
Messages
49
I am trying to import a range from a CSV file into an Excel worksheet.

Code:
'Prompt user for location of alltxt data file
openAlltxt = Application.GetOpenFilename(Title:="Locate alltxt File", MultiSelect:=False)
If openAlltxt = "False" Then
Exit Sub 'exit if they press Cancel
Else
Dim WB As Workbook
Dim Alltxt As Workbook
Set WB = ActiveWorkbook
Set Alltxt = Application.Workbooks.Open(openAlltxt)
Alltxt.ActiveSheet.Range("A1:F200000").Copy
ActiveWorkbook.ActiveWorksheet.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.NumberFormat = "General"
On Error Resume Next
Alltxt.Close False

End If
*End Code

I get the runtime error for the "ActiveWorkbook.ActiveWorksheet" line

Any thoughts?

Thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
That gets rid of the runtime error. However, while the data gets copied correctly from the CSV file, it does not appear in the Excel worksheet.
 
Upvote 0
Maybe it should be like this

Code:
Range("A1:F200000").Copy
ThisWorkbook.Sheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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