これは本当に愚かな方法ですが、3つのユーザー入力を許可するユーザーフォームがあります。テキストファイルテキストファイルの名前、およびテキストファイルからデータをインポートする場所を指定します。私がしたいのは、ユーザーが入力したパスをたどり、ユーザーが入力した名前でテキストファイルを取得し、ユーザーが入力した範囲にテキストファイルの内容を置きます。VBA Excel:ユーザーフォームのテキストボックスを使用してテキストファイルをインポートするパスを指定する
私はそれがApplication.GetOpenFilenameを使用して簡単に簡略化することができますが、あなたは何をしなければならないのか分かります。私がする必要があるのは、パスを指定し、テキストファイルを指定し、テキストファイルからすべてのテキストをカンマ区切り文字で範囲にロードする場所を指定できるようにすることです。現在、プログラムは ".Refresh BackgroundQuery:= False"という行を改行するか、まったく何もしないので、前進する方法はわかりません。私のコードは以下の通りです。もしあなたが助けることができるなら私に教えてください!テキストファイルが配置されているパス、テキストファイルの名前、およびからデータをインポートする場所:
Private Sub OKButton_Click()
Dim filePath As String, destin As String, fileName As Variant
destin = DestinationTextBox.Value
fileName = TextFileNameTextBox.Value
filePath = Dir(FileLocationTextBox.Value)
'filePath = Application.GetOpenFilename("Text Files (*.txt), *.txt")
'oh, if only
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & _
filePath, Destination:=Range(destin))
.Name = fileName & ".txt"
.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 = xlTextQualifierNone
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "" & Chr(10) & ""
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
ます[編集] carifyすることができます –
を私はしました。?それを編集しました。もっと明確にする必要がある場合はお知らせください。 –