• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 74
  • Last Modified:

template creation template

I don't have the slightest idea on what this is called so I will just describe it.  I have a file layout of a text file that identifies that text and what they mean in this garbage of a text file

character 1 - 10 address
11 - 35 last name.
36 - 47 state
48 - 54 state bird

when I import it into excel I have to used a character with tool to define the columns.  is there anyway to repeat this process for the same file layouts so I don't have to adjust the bars everytime?  I do this daily.
1 Solution
jamesmetcalf74Author Commented:
this is the process defined by msft.  can I automate this?

Glenn RayExcel VBA DeveloperCommented:
Yes, you can automate this using VBA.  This code will import a text file with your defined column specifications:
Option Explicit
Sub Import_Text()
    Dim strFileName, strWkbkName As String
    strFileName = Application.GetOpenFilename
    If strFileName = "" Or strFileName = "False" Then Exit Sub
    Workbooks.OpenText Filename:=strFileName, Origin:=437, StartRow:=1, _
        DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(10, 1), _
        Array(35, 1), Array(47, 1))
End Sub

Open in new window

I attached an example file with this code.  Just press the button, browse and locate your file and click the "Open" button.  The data will be inserted in four columns.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now