Dim ff() As String, i As Long
On Error Resume Next
ff = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(ff)
If Dir(App.Path &"\" &ff(i) &".txt") = "" Then
Open App.Path &"\" &ff(i) &".txt" For Output As #1
Print #1, ff(i)
Close #1
End If
Next
MsgBox "文件输出完毕!"
End Sub
Private Sub Form_Load()
Text1.OLEDropMode = 1
End Sub
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ff
Text1.Text = ""
For Each ff In Data.Files
Open ff For Binary As #1
Text1.Text = Text1.Text &Input(LOF(1), #1)
Close #1
Next
End Sub
以上程序生成的txt文件放在程序所在漏陵州文件夹,由于没有返蔽说明文件内容是什么汪耐,就用文件标题作为内容了。另外Text1的MulitLine属性一定要设为True,否则无法换行。此外还要注意文件名的命名规则,即文本框中的内容一定要是适合作为文件名的(比方说不能含有冒号:)。
Dim WordApp As Word.Application'定义word应用变量Dim newDoc As Word.Document'定义word文档变量腊者裤
Set WordApp = CreateObject("Word.Application")'创建新的word应用
WordApp.Visible = True
With WordApp
Set newDoc = .Documents.Add(App.Path &"\报告单\食品水质报告.Doc")'在创建的word应用中新建一个新的word文档
With .Selection
.GoTo wdGoToBookmark, , , "bh" bh为word文档中的对应位置的标签名
.TypeText PrnBID'写内容
.GoTo wdGoToBookmark, , , "GoodsName" 'GoodsName为word文档中的对应位置嫌纯的标签名
.TypeText PrnGName'写内容
Set MyRS = Nothing
End With
'newDoc.SaveAs FileName:=FilePath
End With
'If theError = 429 Then WordApp.Quit
Set WordApp = Nothing
在事先做好的word文档中要写内容的位置设轮简定好标签,然后在程序中找到标签,再写入数据
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)