femma

Board Regular
Joined
Jul 13, 2016
Messages
156
hi!

My code aims to import a csv file and make certain modifications, but I keep getting a 'Sub or Function not Defined'-error.
Any ideas why?

Code:
Sub allofit()
Dim ws As Worksheet, strFile As String
ActiveWorkbook.Sheets.Add After:=Worksheets(Sheets(2))
Set ActiveSheet = ws


strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please select text file...")

With ws.QueryTables.Add(Connection:="TEXT;" & strFile, _
Destination:=ws.Range("A1"))
    .TextFileParseType = xlDelimited
    .TextFileCommaDelimiter = True
    .Refresh

End With
 
ws.Name = "testing"

End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
For one thing, it looks you have one line backwards.
Code:
Set ActiveSheet = ws
should be:
Code:
Set ws = ActiveSheet
When setting variables equal to something, the variable name is always on the left side of the equation.

If you are still getting errors, please let us know exactly which line is returning the error you reference.
 
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,285
Members
449,094
Latest member
GoToLeep

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