
























这段代码给我帮了很大的忙,希望他能帮到更多的人!
1
Public Function copy_mb(file1, file2path) As String
2
Dim fso As Object
3
Dim name
4
name = Date & ((Timer() - 0.0001)) * 10000
5
Set fso = CreateObject("Scripting.FileSystemObject"[img]/images/wink.gif[/img]
6
Set f2 = fso.getfile(file1)
7
f2.Copy (file2path & name & ".doc"[img]/images/wink.gif[/img]
8
Set f2 = Nothing
9
Set fso = Nothing
10
copy_mb = file2path & name & ".doc"
11
End Function
12
13
14
Public Function del_file(filename) As Boolean
15
Dim fso As Object
16
Set fso = CreateObject("Scripting.FileSystemObject"[img]/images/wink.gif[/img]
17
Set f2 = fso.getfile(filename)
18
f2.Delete
19
Set f2 = Nothing
20
Set fso = Nothing
21
End Function
22
23
24
Public Function word_exe(filename, find_str, change_str) As String
25
Dim wdapp As New Word.Application
26
On Error GoTo e1
27
Dim f_str() As String, c_str() As String, i As Integer
28
wdapp.Visible = True
29
wdapp.Documents.Open filename
30
f_str = Split(find_str, "|"[img]/images/wink.gif[/img]
31
c_str = Split(change_str, "|"[img]/images/wink.gif[/img]
32
For i = 0 To UBound(f_str)
33
If Len(c_str(i)) < 255 Then
34
wdapp.ActiveDocument.Content.Find.Execute f_str(i), , True, , , , , , , c_str(i), 2
35
Else
36
Dim j As Integer, n As Integer
37
If (Len(c_str(i)) Mod (254 - Len(f_str(i)))) > 0 Then
38
j = Int(Len(c_str(i)) / (254 - Len(f_str(i)))) + 1
39
Else
40
j = Int(Len(c_str(i)) / (254 - Len(f_str(i))))
41
End If
42
43
For n = 1 To j
44
If n <> j Then
45
wdapp.ActiveDocument.Content.Find.Execute f_str(i), , True, , , , , , , Mid(c_str(i), (n - 1) * (254 - Len(f_str(i))) + 1, 254 - Len(f_str(i))) & f_str(i), 2
46
Else
47
wdapp.ActiveDocument.Content.Find.Execute f_str(i), , True, , , , , , , Mid(c_str(i), (n - 1) * (254 - Len(f_str(i))) + 1, Len(c_str(i)) - (n - 1) * (254 - Len(f_str(i)))), 2
48
End If
49
Next n
50
End If
51
52
Next i
53
54
wdapp.ActiveDocument.Save
55
wdapp.ActiveDocument.Close
56
wdapp.Quit
57
58
Set wdapp = Nothing
59
word_exe = "OK"
60
Exit Function
61
62
e1:
63
wdapp.Quit
64
Set wdapp = Nothing
65
Dim ErrMsg As String
66
ErrMsg = "Error Number:" & Err.Number & "<br><br>"
67
ErrMsg = ErrMsg & "Error Source:" & Err.Source & "<br><br>"
68
ErrMsg = ErrMsg & "Error Description:" & Err.Description & "<br><br>"
69
word_exe = ErrMsg
70
Exit Function
71
72
End Function
73
74
75
76
Public Function open_word(filename)
77
Dim wdapp As New Word.Application
78
wdapp.Visible = True
79
wdapp.Documents.Open filename
80
End Function
81
82
83
84
Public Function copy_file(file1, file2, openstr) As String
85
Dim fso As Object
86
Set fso = CreateObject("Scripting.FileSystemObject"[img]/images/wink.gif[/img]
87
Set f2 = fso.getfile(file1)
88
f2.Copy (file2)
89
Set f2 = Nothing
90
Set fso = Nothing
91
copy_file = file2
92
If openstr = "yes" Then
93
Call open_word(file2)
94
End If
95
End Function
96
97
98
99
Public Function open_new(filename) As String
100
Dim wpsapp As New Word.Application
101
wpsapp.Documents.Add
102
wpsapp.Documents(1).SaveAs filename
103
wpsapp.Documents.Open filename
104
wpsapp.Visible = True
105
open_new = filename
106
End Function
107
108
109
110
Public Function copy_content(filename) As String
111
Dim wdapp As New Word.Application
112
wdapp.Visible = False
113
wdapp.Documents.Open filename
114
wdapp.Selection.WholeStory
115
copy_content = wdapp.Selection.Text
116
wdapp.ActiveDocument.Close
117
wdapp.Quit
118
Set wdapp = Nothing
119
End Function
120
121
122
123
Public Function copy_content2(filename) As String
124
Dim wdapp As New Word.Application
125
wdapp.Visible = False
126
wdapp.Documents.Open filename
127
wdapp.Selection.WholeStory
128
wdapp.Selection.Copy
129
copy_content2 = "已复制内容到剪贴板!!"
130
wdapp.ActiveDocument.Close
131
wdapp.Quit
132
Set wdapp = Nothing
133
End Function
134
135
136
137
138
Public Sub create_obj(a, b, c)
139
Dim obj As New WebFile
140
Call obj.HTTPPutFileEx(a, b, c)
141
Set obj = Nothing
142
End Sub
143
144
145
146
Public Sub get_obj(a, b, c)
147
Dim obj As New WebFile
148
Call obj.HTTPGetFile(a, b, c)
149
End Sub
150
151
152
153
154
vbscript中的处理方法:
155
=========================================
156
157
以下内容为程序代码:
158
159
<script language="vbscript">
160
161
On Error Resume Next
162
163
Dim wApp
164
165
Set wApp = CreateObject("Word.Application"[img]/images/wink.gif[/img]
166
If Err.number > 0 Then
167
Alert "没法保存为Word文件,请正确安装Word软件"
168
else
169
wApp.visible = True
170
//
.操作代码!
171
end if
172
173
174
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。