I am using Excel VBA and lot of people helped me to overcome challengers as a new VBA user.
I am using the following code to open a txt file using excel VBA command button, but it open as a separate txt file, I need the first sheet of this opened txt file to automatically select to the clip board and paste in the template I am using. And close the txt file as it is not necessary.
The file name of this txt file is not unique and it should record in the program memory as a variable (I believe string)
Private Sub CommandButton1_Click()
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = "I:\Group"
.Filters.Clear
.Title = "Your Title"
If Not .Show Then
MsgBox "No file selected.": Exit Sub
End If
Workbooks.OpenText .SelectedItems(1), Origin:=xlMSDOS, StartRow:=23, DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(6, 2), Array(23, 1), Array(30, 2), Array(63, 2), Array(68, 1), _
Array(77, 4), Array(88, 4), Array(101, 1), Array(117, 1)), TrailingMinusNumbers:= _
True
End With
End Sub