ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automate text import (https://www.excelbanter.com/excel-programming/289307-automate-text-import.html)

Jamie Abbamont

Automate text import
 
Hi. I'm new to writing macros, and I've been asked to write a macro that imports colon delimited text files into excel. I need to create the macro so that the user is prompted for the file to import. I used the macro recorder, but I cannot get it to work using a variable. Can anyone lend a hand

-Jamie

acw[_2_]

Automate text import
 
Jami

Is this the type of thing that you mean

Ton

getfilename = InputBox("Enter the file name including path", , "c:\temp\aaa.txt"
Workbooks.OpenText FileName:=getfilename, Origin:=xlWindows,
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False
, Space:=False, Other:=True, OtherChar:=":", FieldInfo:=Array(Array(1, 1
), Array(2, 1), Array(3, 1)

----- Jamie Abbamont wrote: ----

Hi. I'm new to writing macros, and I've been asked to write a macro that imports colon delimited text files into excel. I need to create the macro so that the user is prompted for the file to import. I used the macro recorder, but I cannot get it to work using a variable. Can anyone lend a hand

-Jamie

mudraker[_130_]

Automate text import
 
Jamie

Try this version

Gives user normal Open file dialog box


Sub OpenFile()
Dim sFile As String

sFile$ = Application.GetOpenFilename("Text Files (*.*),*.txt")
If sFile = "False" Then
End
End If
Workbooks.OpenText FileName:= _
sFile, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True
_
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2,
1), _
Array(3, 1), Array(4, 1))
End Sub


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 06:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com