Change macro from acting on specific txt file to prompting for txt file

stevieg

New Member
Joined
Feb 14, 2014
Messages
1
Hi,

I have recorded a macro to import a .txt file with a specific path, 'Macintosh HD:Users:Stephen.....' which contains some scientific information, and to format the text to only keep the data I want, and then to save it as a .xls spreadsheet.

I want the macro to prompt me for a .txt file when I run it rather than operating on only the one whose path is currently specified in the macro.

Can anyone help me or tell me where to look for an answer? Any help would be much appreciated, thanks.
---------
The macro code is below.
Sub Macro3()
'
' Macro3 Macro
'


'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Macintosh HD:Users:Stephen:Documents:Chemistry:Postdoc:Experiments:37 Syed La0.52Ca0.28Ni0.06Ti0.94O3:131220 sequence files pre-reduced biogas:SYBG0005.D:Report.TXT" _
, Destination:=Range("A1"))
.Name = "Report"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlMacintosh
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(9, 9, 1, 1, 9, 9, 1, 9, 9, 9)
.Refresh BackgroundQuery:=False
.UseListObject = False
End With
Rows("3:25").Select
Selection.Delete Shift:=xlUp
Rows("8:28").Select
Selection.Delete Shift:=xlUp
Range("A3:B7").Select
Selection.Delete Shift:=xlToLeft
Range("A3").Select
Selection.Copy
Range("E4").Select
ActiveSheet.Paste
Range("A6").Select
Application.CutCopyMode = False
Selection.Copy
Range("B4").Select
ActiveSheet.Paste
Range("A5").Select
Application.CutCopyMode = False
Selection.Copy
Range("C4").Select
ActiveSheet.Paste
Range("A7").Select
Application.CutCopyMode = False
Selection.Copy
Range("D4").Select
ActiveSheet.Paste
Rows("3:3").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Rows("4:6").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="\", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _
1), Array(6, 1))
Range("A1:E1").Select
Range("E1").Activate
Selection.Delete Shift:=xlToLeft
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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