0

こんにちは私は特定のドライブの特定のテキストファイルからデータを挿入するマクロを持っています(K:...などのbrowleft.txt)が、Excelワークシートのドライブとフォルダからマクロを読み取れるようにしたいと思いますがあり、変数名が同じ末尾のテキストファイル(alexbrowleft.txtやgrahambrowright.txtなど)からも可能です...これは可能であり、誰かが私を助けることができます...これが以下のマクロです。 ..

Sub insert()
'
' insert Macro
' insert
'
' Keyboard Shortcut: Ctrl+i
'
    Range("A4").Select
    ActiveCell.FormulaR1C1 = "left brow"
    Range("B4").Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;K:\browleft.txt", _
        Destination:=Range("$B$4"))
        .Name = "browleft_8"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
        , 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .refresh BackgroundQuery:=False
    End With
    Range("A6").Select
    ActiveCell.FormulaR1C1 = "right brow"
    Range("B6").Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;K:\browright.txt", _
        Destination:=Range("$B$6"))
        .Name = "browright_8"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
        , 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .refresh BackgroundQuery:=False
    End With
    Range("A8").Select
    ActiveCell.FormulaR1C1 = "eye left"
    Range("B8").Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;K:\eyeleft.txt", _
        Destination:=Range("$B$8"))
        .Name = "eyeleft_8"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
        , 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .refresh BackgroundQuery:=False
    End With
    Range("A10").Select
    ActiveCell.FormulaR1C1 = "right eye"
    Range("B10").Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;K:\eyeright.txt", _
        Destination:=Range("$B$10"))
        .Name = "eyeright_8"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
        , 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .refresh BackgroundQuery:=False
    End With
    Range("A12").Select
    ActiveCell.FormulaR1C1 = "jaw"
    Range("B12").Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;K:\jaw.txt", Destination _
        :=Range("$B$12"))
        .Name = "jaw_8"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
        , 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .refresh BackgroundQuery:=False
    End With
    Range("A14").Select
    ActiveCell.FormulaR1C1 = "mouth height"
    Range("B14").Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;K:\mouthheight.txt", _
        Destination:=Range("$B$14"))
        .Name = "mouthheight_8"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
        , 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .refresh BackgroundQuery:=False
    End With
    Range("A16").Select
    ActiveCell.FormulaR1C1 = "mouth width"
    Range("B16").Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;K:\mouthwidth.txt", _
        Destination:=Range("$B$16"))
        .Name = "mouthwidth_8"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
        , 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .refresh BackgroundQuery:=False
    End With
    Range("A18").Select
    ActiveCell.FormulaR1C1 = "nostrils"
    Range("B18").Select
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;K:\nostrils.txt", _
        Destination:=Range("$B$18"))
        .Name = "nostrils_9"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
        , 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .refresh BackgroundQuery:=False
    End With
    Range("17:17,15:15,13:13,11:11,9:9,7:7,5:5").Select
    Range("A5").Activate
    Selection.Delete Shift:=xlUp
    Range("A4").Select
    ActiveCell.FormulaR1C1 = "Left Brow"
    Range("A5").Select
    ActiveCell.FormulaR1C1 = "Right Brow"
    Range("A6").Select
    ActiveCell.FormulaR1C1 = "Eye Left"
    Range("A7").Select
    ActiveCell.FormulaR1C1 = "Eye Right"
    Range("A8").Select
    ActiveCell.FormulaR1C1 = "Jaw"
    Range("A9").Select
    ActiveCell.FormulaR1C1 = "Mouth Height"
    Range("A10").Select
    ActiveCell.FormulaR1C1 = "Mouth Width"
    Range("A11").Select
    ActiveCell.FormulaR1C1 = "Nostrils"
    Range("A12").Select
End Sub
Sub deletedata()
'
' deletedata Macro
'
' Keyboard Shortcut: Ctrl+d
'
    Range("B4").Select
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 15
    ActiveWindow.ScrollColumn = 23
    ActiveWindow.ScrollColumn = 30
    ActiveWindow.ScrollColumn = 35
    ActiveWindow.ScrollColumn = 40
    ActiveWindow.ScrollColumn = 46
    ActiveWindow.ScrollColumn = 52
    ActiveWindow.ScrollColumn = 58
    ActiveWindow.ScrollColumn = 62
    ActiveWindow.ScrollColumn = 67
    ActiveWindow.ScrollColumn = 71
    ActiveWindow.ScrollColumn = 75
    ActiveWindow.ScrollColumn = 79
    ActiveWindow.ScrollColumn = 83
    ActiveWindow.ScrollColumn = 86
    ActiveWindow.ScrollColumn = 90
    ActiveWindow.ScrollColumn = 94
    ActiveWindow.ScrollColumn = 98
    ActiveWindow.ScrollColumn = 103
    ActiveWindow.ScrollColumn = 107
    ActiveWindow.ScrollColumn = 111
    ActiveWindow.ScrollColumn = 116
    ActiveWindow.ScrollColumn = 120
    ActiveWindow.ScrollColumn = 124
    ActiveWindow.ScrollColumn = 129
    ActiveWindow.ScrollColumn = 133
    ActiveWindow.ScrollColumn = 138
    ActiveWindow.ScrollColumn = 142
    ActiveWindow.ScrollColumn = 146
    ActiveWindow.ScrollColumn = 149
    ActiveWindow.ScrollColumn = 153
    ActiveWindow.ScrollColumn = 156
    ActiveWindow.ScrollColumn = 163
    ActiveWindow.ScrollColumn = 170
    ActiveWindow.ScrollColumn = 176
    ActiveWindow.ScrollColumn = 181
    ActiveWindow.ScrollColumn = 187
    ActiveWindow.ScrollColumn = 193
    ActiveWindow.ScrollColumn = 199
    ActiveWindow.ScrollColumn = 204
    ActiveWindow.ScrollColumn = 208
    ActiveWindow.ScrollColumn = 211
    ActiveWindow.ScrollColumn = 214
    ActiveWindow.ScrollColumn = 216
    ActiveWindow.ScrollColumn = 218
    ActiveWindow.ScrollColumn = 219
    ActiveWindow.ScrollColumn = 221
    ActiveWindow.ScrollColumn = 222
    ActiveWindow.ScrollColumn = 223
    ActiveWindow.ScrollColumn = 224
    ActiveWindow.ScrollColumn = 225
    ActiveWindow.ScrollColumn = 226
    ActiveWindow.ScrollColumn = 227
    ActiveWindow.ScrollColumn = 228
    ActiveWindow.ScrollColumn = 229
    ActiveWindow.ScrollColumn = 230
    ActiveWindow.ScrollColumn = 231
    ActiveWindow.ScrollColumn = 233
    ActiveWindow.ScrollColumn = 234
    ActiveWindow.ScrollColumn = 236
    ActiveWindow.ScrollColumn = 238
    ActiveWindow.ScrollColumn = 240
    ActiveWindow.ScrollColumn = 243
    ActiveWindow.ScrollColumn = 244
    ActiveWindow.ScrollColumn = 247
    ActiveWindow.ScrollColumn = 248
    ActiveWindow.ScrollColumn = 250
    ActiveWindow.ScrollColumn = 252
    ActiveWindow.ScrollColumn = 253
    ActiveWindow.ScrollColumn = 254
    ActiveWindow.ScrollColumn = 255
    ActiveWindow.ScrollColumn = 256
    ActiveWindow.ScrollColumn = 257
    ActiveWindow.ScrollColumn = 258
    ActiveWindow.ScrollColumn = 256
    ActiveWindow.ScrollColumn = 252
    ActiveWindow.ScrollColumn = 232
    ActiveWindow.ScrollColumn = 223
    ActiveWindow.ScrollColumn = 214
    ActiveWindow.ScrollColumn = 204
    ActiveWindow.ScrollColumn = 196
    ActiveWindow.ScrollColumn = 186
    ActiveWindow.ScrollColumn = 176
    ActiveWindow.ScrollColumn = 166
    ActiveWindow.ScrollColumn = 157
    ActiveWindow.ScrollColumn = 148
    ActiveWindow.ScrollColumn = 141
    ActiveWindow.ScrollColumn = 135
    ActiveWindow.ScrollColumn = 130
    ActiveWindow.ScrollColumn = 125
    ActiveWindow.ScrollColumn = 120
    ActiveWindow.ScrollColumn = 116
    ActiveWindow.ScrollColumn = 112
    ActiveWindow.ScrollColumn = 109
    ActiveWindow.ScrollColumn = 108
    ActiveWindow.ScrollColumn = 107
    ActiveWindow.ScrollColumn = 105
    ActiveWindow.ScrollColumn = 103
    ActiveWindow.ScrollColumn = 101
    ActiveWindow.ScrollColumn = 99
    ActiveWindow.ScrollColumn = 97
    ActiveWindow.ScrollColumn = 94
    ActiveWindow.ScrollColumn = 91
    ActiveWindow.ScrollColumn = 88
    ActiveWindow.ScrollColumn = 86
    ActiveWindow.ScrollColumn = 83
    ActiveWindow.ScrollColumn = 81
    ActiveWindow.ScrollColumn = 79
    ActiveWindow.ScrollColumn = 78
    ActiveWindow.ScrollColumn = 77
    ActiveWindow.ScrollColumn = 76
    ActiveWindow.ScrollColumn = 75
    ActiveWindow.ScrollColumn = 74
    ActiveWindow.ScrollColumn = 72
    ActiveWindow.ScrollColumn = 71
    ActiveWindow.ScrollColumn = 70
    ActiveWindow.ScrollColumn = 69
    ActiveWindow.ScrollColumn = 68
    ActiveWindow.ScrollColumn = 67
    ActiveWindow.ScrollColumn = 66
    ActiveWindow.ScrollColumn = 65
    ActiveWindow.ScrollColumn = 64
    ActiveWindow.ScrollColumn = 63
    ActiveWindow.ScrollColumn = 62
    ActiveWindow.ScrollColumn = 60
    ActiveWindow.ScrollColumn = 58
    ActiveWindow.ScrollColumn = 56
    ActiveWindow.ScrollColumn = 52
    ActiveWindow.ScrollColumn = 50
    ActiveWindow.ScrollColumn = 46
    ActiveWindow.ScrollColumn = 43
    ActiveWindow.ScrollColumn = 40
    ActiveWindow.ScrollColumn = 38
    ActiveWindow.ScrollColumn = 37
    ActiveWindow.ScrollColumn = 36
    ActiveWindow.ScrollColumn = 35
    ActiveWindow.ScrollColumn = 34
    ActiveWindow.ScrollColumn = 35
    ActiveWindow.ScrollColumn = 41
    ActiveWindow.ScrollColumn = 44
    ActiveWindow.ScrollColumn = 47
    ActiveWindow.ScrollColumn = 52
    ActiveWindow.ScrollColumn = 58
    ActiveWindow.ScrollColumn = 64
    ActiveWindow.ScrollColumn = 70
    ActiveWindow.ScrollColumn = 77
    ActiveWindow.ScrollColumn = 86
    ActiveWindow.ScrollColumn = 97
    ActiveWindow.ScrollColumn = 106
    ActiveWindow.ScrollColumn = 116
    ActiveWindow.ScrollColumn = 124
    ActiveWindow.ScrollColumn = 131
    ActiveWindow.ScrollColumn = 138
    ActiveWindow.ScrollColumn = 144
    ActiveWindow.ScrollColumn = 150
    ActiveWindow.ScrollColumn = 156
    ActiveWindow.ScrollColumn = 161
    ActiveWindow.ScrollColumn = 167
    ActiveWindow.ScrollColumn = 173
    ActiveWindow.ScrollColumn = 180
    ActiveWindow.ScrollColumn = 188
    ActiveWindow.ScrollColumn = 195
    ActiveWindow.ScrollColumn = 202
    ActiveWindow.ScrollColumn = 209
    ActiveWindow.ScrollColumn = 215
    ActiveWindow.ScrollColumn = 221
    ActiveWindow.ScrollColumn = 227
    ActiveWindow.ScrollColumn = 233
    ActiveWindow.ScrollColumn = 239
    ActiveWindow.ScrollColumn = 245
    ActiveWindow.ScrollColumn = 250
    ActiveWindow.ScrollColumn = 254
    ActiveWindow.ScrollColumn = 258
    Range("B4:JZ11").Select
    ActiveWindow.ScrollColumn = 257
    ActiveWindow.ScrollColumn = 252
    ActiveWindow.ScrollColumn = 242
    ActiveWindow.ScrollColumn = 237
    ActiveWindow.ScrollColumn = 232
    ActiveWindow.ScrollColumn = 227
    ActiveWindow.ScrollColumn = 221
    ActiveWindow.ScrollColumn = 214
    ActiveWindow.ScrollColumn = 207
    ActiveWindow.ScrollColumn = 200
    ActiveWindow.ScrollColumn = 182
    ActiveWindow.ScrollColumn = 172
    ActiveWindow.ScrollColumn = 162
    ActiveWindow.ScrollColumn = 152
    ActiveWindow.ScrollColumn = 144
    ActiveWindow.ScrollColumn = 134
    ActiveWindow.ScrollColumn = 125
    ActiveWindow.ScrollColumn = 118
    ActiveWindow.ScrollColumn = 111
    ActiveWindow.ScrollColumn = 105
    ActiveWindow.ScrollColumn = 99
    ActiveWindow.ScrollColumn = 92
    ActiveWindow.ScrollColumn = 86
    ActiveWindow.ScrollColumn = 80
    ActiveWindow.ScrollColumn = 75
    ActiveWindow.ScrollColumn = 70
    ActiveWindow.ScrollColumn = 65
    ActiveWindow.ScrollColumn = 60
    ActiveWindow.ScrollColumn = 56
    ActiveWindow.ScrollColumn = 52
    ActiveWindow.ScrollColumn = 48
    ActiveWindow.ScrollColumn = 44
    ActiveWindow.ScrollColumn = 41
    ActiveWindow.ScrollColumn = 38
    ActiveWindow.ScrollColumn = 34
    ActiveWindow.ScrollColumn = 30
    ActiveWindow.ScrollColumn = 26
    ActiveWindow.ScrollColumn = 23
    ActiveWindow.ScrollColumn = 17
    ActiveWindow.ScrollColumn = 12
    ActiveWindow.ScrollColumn = 7
    ActiveWindow.ScrollColumn = 1
    Rows("4:11").Select
    Selection.ClearContents
End Sub
Sub refresh()
'
' refresh Macro
' refresh values
'
' Keyboard Shortcut: Ctrl+r
'
    Range("E4").Select
    ActiveCell.FormulaR1C1 = "='OSC '!RC[-3]"
    Range("E4").Select
    Selection.AutoFill Destination:=Range("E4:JZ4"), Type:=xlFillDefault
    Range("E4:JZ4").Select
    Selection.AutoFill Destination:=Range("E4:JZ11"), Type:=xlFillDefault
    Range("E4:JZ11").Select
    ActiveWindow.ScrollColumn = 258
    ActiveWindow.ScrollColumn = 253
    ActiveWindow.ScrollColumn = 246
    ActiveWindow.ScrollColumn = 235
    ActiveWindow.ScrollColumn = 227
    ActiveWindow.ScrollColumn = 218
    ActiveWindow.ScrollColumn = 200
    ActiveWindow.ScrollColumn = 193
    ActiveWindow.ScrollColumn = 186
    ActiveWindow.ScrollColumn = 180
    ActiveWindow.ScrollColumn = 174
    ActiveWindow.ScrollColumn = 169
    ActiveWindow.ScrollColumn = 163
    ActiveWindow.ScrollColumn = 157
    ActiveWindow.ScrollColumn = 152
    ActiveWindow.ScrollColumn = 146
    ActiveWindow.ScrollColumn = 141
    ActiveWindow.ScrollColumn = 135
    ActiveWindow.ScrollColumn = 131
    ActiveWindow.ScrollColumn = 125
    ActiveWindow.ScrollColumn = 120
    ActiveWindow.ScrollColumn = 114
    ActiveWindow.ScrollColumn = 103
    ActiveWindow.ScrollColumn = 98
    ActiveWindow.ScrollColumn = 92
    ActiveWindow.ScrollColumn = 86
    ActiveWindow.ScrollColumn = 81
    ActiveWindow.ScrollColumn = 75
    ActiveWindow.ScrollColumn = 71
    ActiveWindow.ScrollColumn = 66
    ActiveWindow.ScrollColumn = 61
    ActiveWindow.ScrollColumn = 57
    ActiveWindow.ScrollColumn = 54
    ActiveWindow.ScrollColumn = 52
    ActiveWindow.ScrollColumn = 49
    ActiveWindow.ScrollColumn = 48
    ActiveWindow.ScrollColumn = 46
    ActiveWindow.ScrollColumn = 44
    ActiveWindow.ScrollColumn = 41
    ActiveWindow.ScrollColumn = 39
    ActiveWindow.ScrollColumn = 36
    ActiveWindow.ScrollColumn = 32
    ActiveWindow.ScrollColumn = 28
    ActiveWindow.ScrollColumn = 24
    ActiveWindow.ScrollColumn = 21
    ActiveWindow.ScrollColumn = 18
    ActiveWindow.ScrollColumn = 15
    ActiveWindow.ScrollColumn = 13
    ActiveWindow.ScrollColumn = 10
    ActiveWindow.ScrollColumn = 7
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 1
    Range("A2").Select
End Sub
4

2 に答える 2

0

物事をダイナミックにすることに少し光を当てます

プロセスを少し動的にしたい場合は、実際にはファイルのパス/名前を含むセルを作成し、そのセルから読み取るようにマクロを指定できます:)したがって、ファイル名を変更するために常にマクロに入る必要はありません。 。

さらに、その場合は、ハードドライブのどこからでも入力テキストファイルを読み取ることができます。覚えておく必要はありません。そのフルパス/ファイル名をセルにコピーして貼り付けるだけです:)

次に、正規表現LIKEを使用して、xyzまたはyzx...にする必要のあるファイル名を指定する別のセルを作成できます。それはさらに複雑になる可能性があるので、ここでは単純さが鍵となるので、私はそれを脇に置いておきます。

次のサンプルをご覧ください。

ファイル名はbrowleft.txt。ファイルのフルパスがセル「A2」にあると想定します。たとえばK:\ 、アプリケーションファイルと同じフォルダでテキストファイルを検索する場合は、この「A2」セルを空のままにしておくことができます。(このExcel作業ファイル)ファイル名を「A3」に入力=brownleft.txt 名前が表示されるワイルドカード文字列LIKE=alex セル「A4」に入力

Dim strFilePath as String
Dim strFileName as String
Dim strWildCard as String
Dim rngPath as Range
Dim rngName as Range

set rngPath = Range("A2")
set rngName = Range("A3")
set rngWild = Range("A4")

'--- Validate your inputs before processing


If Trim(rngWild.value) <> "" Then
  strWildCard = Trim(rngWild.value)
Else
  strWildCard = "alex" '--- the default wildcard string
End If

If Trim(rngName.value) <> "" Then
  strFileName = Trim(rngName.value)
Else
  strFileName = "brownleft.txt" '--- the default file name
End If

If Trim(rngPath.value) <> "" Then
  strFilePath = Trim(rngPath.value) & strWildCard & strFileName
Else
  strFilePath = ThisWorkbook.Path & "\" & strWildCard & strFileName
    End If

    With ActiveSheet.QueryTables.Add(Connection:="TEXT;strFilePath, _
    ...
..

残りは続きます:)

于 2012-11-27T15:31:09.857 に答える
0

マクロを含むワークブックへのパスを意味すると仮定するとinsert()、次を使用してファイル名と組み合わせることができます。

ファイルがあるディレクトリへのパスを取得するには、次を使用します。

ThisWorkbook.Path

ファイル名を含むフル パスを取得するには、次を使用します。

ThisWorkbook.FullName

例:

Dim sFilePath as String
Dim sName as String

sName = "alex"
sFilePath = ThisWorkbook.Path & "\" & sName & "browleft.txt"

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & sFilePath, _
于 2012-11-27T12:57:54.367 に答える