【发布时间】:2015-01-20 03:54:02
【问题描述】:
我正在使用 Excel VBA,作为 VBA 新用户,很多人帮助我克服了挑战。
我正在使用以下代码使用excel VBA命令按钮打开一个txt文件,但它作为一个单独的txt文件打开,我需要这个打开的txt文件的第一张自动选择到剪贴板并粘贴到我正在使用的模板。并关闭txt文件,因为没有必要。
这个txt文件的文件名不是唯一的,应该作为变量记录在程序内存中(我相信是字符串)
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
【问题讨论】:
-
打开我们在stackoverflow.com/questions/27957741/…讨论过的文件
-
我只是整理了一下方法……