Error with VBA to copy data from txt file to excel

uhd04

New Member
Joined
Jan 23, 2014
Messages
3
Hi,

i have a report created in txt using a powershell script and i'm trying to import data from report to excel using QueryTable. The report is similar to this but have much more rows


ClusterNameNodeState
--------------------
Server1Cluster DiskServer1-nodeAOnline
Server1Cluster IP AddressServer1-nodeAOnline
ClusterNameNodeState
--------------------
Server2Disk D:Server2-nodeAOnline
Server2Disk E:Server2-nodeAOnline
Server2DiskF:Server2-nodeAOnline
Server2IP AddressServer2-nodeAOffline
Server2Server ServicesServer2-nodeAOffline
Server2Network NameServer2-nodeAOnline
Server2SpoolerServer2-nodeAOnline
Server2Communiquez ABCDEF ServiceServer2-nodeAOnline
Server2Nettoyant Analyse Notice Look-up ServiceServer2-nodeAOnline

<tbody>
</tbody>


And when i import it using vba to excel it comes up like this (Bold are the errors occurred while importing data)

ClusterNameNodeState
--------------------
Server1Cluster DiskServer1-nodeAOnline
Server1Cluster IP AddressServer1-nodeAOnline
ClusterNameNode State
--------------- -----
Server2Disk D:Server2-nodeA Online
Server2Disk E:Server2-nodeA Online
Server2Disk F:Server2-nodeA Online
Server2IP AddressServer2-nodeA Offline
Server2Server ServicesServer2-nodeA Offline
Server2Network NameServer2-nodeA Online
Server2SpoolerServer2-nodeA Online
Server2Communiquez ABCDEF Service Server2-nodeA Online
Server2Nettoyant Analyse Notice Look-up Service Server2-nodeA Online

<tbody>
</tbody>


























the QueryTable i'm using is

Code:
Sub ImportReport()
    
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;c:\CluterReport.txt", Destination:=Range( _
        "$A$1"))
        .Name = "CluRes_Log"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 1252
        .TextFileStartRow = 1
        .TextFileParseType = xlFixedWidth
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
        .TextFileFixedColumnWidths = Array(14, 15, 19, 24)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub

So could someone please advise on what i should change/update in my code or if there is another efficient way that i get the report like the below, i mean all columns are imported properly. Thanks

ClusterNameNodeState
--------------------
Server1Cluster DiskServer1-nodeAOnline
Server1Cluster IP AddressServer1-nodeAOnline
ClusterNameNodeState
--------------------
Server2Disk D:Server2-nodeAOnline
Server2Disk E:Server2-nodeAOnline
Server2DiskF:Server2-nodeAOnline
Server2Virtual IP AddressServer2-nodeAOffline
Server2Virtual Server NameServer2-nodeAOffline
Server2Network NameServer2-nodeAOnline
Server2SpoolerServer2-nodeAOnline
Server2Communiquez ABCDEF ServiceServer2-nodeAOnline
Server2Nettoyant Analyse Notice Look-up ServiceServer2-nodeAOnline

<tbody>
</tbody>
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

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