Jump to content

Recommended Posts

Posted

Hi,

 

I have this VBA macro which sort imports data from a text file.

I do not know exactly how to make it good.

 

I have two sheets, named

 

On sheet I made a command button with this code:

 

Private Sub CommandButton1_Click()
'
' Macro1 Macro
' Macro recorded 2/17/2008 by Hack
'

'
   
   With ActiveSheet.QueryTables.Add(Connection:= _
       "TEXT;H:\MyPath\test.txt", _
       Destination:=Range("A1"))
       .Name = "test.txt"
       .FieldNames = True
       .RowNumbers = True
       .FillAdjacentFormulas = False
       .PreserveFormatting = True
       .RefreshOnFileOpen = True
       .RefreshStyle = xlOverwriteCells
       .SavePassword = False
       .SaveData = False
       .AdjustColumnWidth = True
       .RefreshPeriod = 0
       .TextFilePromptOnRefresh = False
       .TextFilePlatform = xlWindows
       .TextFileStartRow = 1
       .TextFileParseType = xlDelimited
       .TextFileTextQualifier = xlTextQualifierDoubleQuote
       .TextFileConsecutiveDelimiter = False
       .TextFileTabDelimiter = True
       .TextFileSemicolonDelimiter = False
       .TextFileCommaDelimiter = False
       .TextFileSpaceDelimiter = False
       .TextFileColumnDataTypes = Array(2)
       .Refresh BackgroundQuery:=False
   End With
End Sub

When I click it, it imports information from a textfile as you see.

Allthough the information is printed out on sheet where the button is.

I bet it has something to do with "With ActiveSheet" statement.

I want the data from the textfile to be prionted in sheet .

 

How?

 

And my second question is how can this macro import data from all *.txt files under a certain path.

In this case it's only one file.

Is it like:

"TEXT;H:\MyPath\*.txt", _

.Name = "*.txt"

 

 

:)

 

Thanx

Posted

Forgive me if I'm wrong but that looks morelike an Excel macro than an AutoCAD macro ?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...