Macro to Import a data file

braju

New Member
Joined
May 1, 2002
Messages
14
I am trying to create a macro to import a data file which is in .PRN format. I was able create macro to open the file, But i dont have an option to open a diiferent file each time.

I need some help to create a file popup menu to select the data file. The file has to be imported to a different sheet.

This is my recorded Macro code to do the function:

Sub Import()
'
' '
Sheets("Raw Data").Select
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;G:PRN'ssp01020402.prn" _
, Destination:=Range("A1"))
.Name = "sp01020402_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.Refresh BackgroundQuery:=False
End With
End Sub

Please help me create a popup menu to Selct a particular data file
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I guess it helps but i dont where i need to place the getopenfile()function in my code.

help Wanted......
 
Upvote 0
This will prompt to choose location and only ".xls" files. If you need to view other files then change the parameters.

sub ImportFile ()
dim fileToOpen as string

fileToOpen = Application.GetOpenFilename("Microsoft Excel Files (*.xls), *.xls")
If fileToOpen <> False Then
Workbooks.Open fileToOpen
Range("A6").Select
Else
Exit Sub
End If


end Sub
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,291
Members
448,564
Latest member
ED38

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