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
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