Hjælp til makro
Hej,Har nedenstående makro der skal importere data fra en text-fil med fast kolonner bredder, men jeg får fejl ved kørsel af makroen.
--------------------------------------------------------------
Fejlen er flg.:
Run-time error '1004'
Microsoft Office Excel cannot access the file C:\...\balance.txt. There are several possible reasons:
- The filename or path does not exist.
- The file is being used by another program.
- The workbook you are trying to save has the same as a
---------------------------------------------------------------
Sub ImportTrialBalance()
Dim qryTable As QueryTable
Dim rngDestination As Range
Dim strConnection As String
'Open sheet for ImportTrailBalance
Sheets("ImportTrialBalance").Select
'Define the connection string and destination range
strConnection = "TEXT;C:\Documents and Settings\hma\Desktop\balance.txt"
Set rngDestination = Sheet2.Range("A1")
'Create QueryTable
Set qryTable = Sheet2.QueryTables.Add(strConnection, rngDestination)
'Populate the QueryTable
qryTable.TextFileStartRow = 10
qryTable.TextFileParseType = xlFixedWidth
qryTable.TextFileCommaDelimiter = False
qryTable.TextFileTextQualifier = xlTextQualifierNone
qryTable.TextFileFixedColumnWidths = Array(0, 1, 13, 5, 1, 32, 1, 18, 1, 17, 3, 17, 1, 17, 3, 17, 1, 18)
qryTable.TextFileTrailingMinusNumbers = True
qryTable.Refresh BackgroundQuery:=False
End Sub
----------------------------------------------------------------
