Browsen naar de txt-file gaat ook niet op deze manier. Als je dat echt wilt moet je in de VB-editor maar eens zoeken naar "dialog". Ik heb even een code-voorbeeldje voor je gemaakt, de rest mag je zelf proberen:
Simpel voorbeeld, opgenomen met de macro-recorder
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| With ActiveSheet.QueryTables.Add(Connection:="TEXT;D:\My Documents\Desktop\Book1.txt", Destination:=Range("A1"))
.Name = "Book1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With |
Dezelfde code, maar nu aangepast zodat je zelf de bestandsnaam kunt opgeven:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| Dim Bestandsnaam1, myFSO
Set myFSO = CreateObject("Scripting.FileSystemObject")
While Not myFSO.FileExists(Bestandsnaam1) = True
Bestandsnaam1 = InputBox("Wat is het volledige pad naar het eerste bestand?", "Geef bestandsnaam1")
Wend
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Bestandsnaam1, Destination:=Range("A1"))
.Name = "Book1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With |
[
Voor 7% gewijzigd door
Arnaud op 05-03-2003 15:59
. Reden: stukje toegevoegd over zoeken naar "dialog" ]