惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
博客园 - 司徒正美
美团技术团队
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Troy Hunt's Blog
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
B
Blog
NISL@THU
NISL@THU
月光博客
月光博客
博客园 - 【当耐特】
AWS News Blog
AWS News Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
腾讯CDC
L
Lohrmann on Cybersecurity
The Cloudflare Blog
L
LINUX DO - 最新话题
S
Security @ Cisco Blogs
S
Secure Thoughts
Spread Privacy
Spread Privacy
有赞技术团队
有赞技术团队
The Last Watchdog
The Last Watchdog
Project Zero
Project Zero
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
H
Hacker News: Front Page
S
SegmentFault 最新的问题
Schneier on Security
Schneier on Security
aimingoo的专栏
aimingoo的专栏
P
Privacy & Cybersecurity Law Blog
博客园 - 三生石上(FineUI控件)
Forbes - Security
Forbes - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
I
InfoQ
T
Tailwind CSS Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
GRAHAM CLULEY
W
WeLiveSecurity
小众软件
小众软件
Recorded Future
Recorded Future
Cyberwarzone
Cyberwarzone
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

博客园 - 柴火

SqlServer死锁处理存储过程 DB2常用SQL的写法(未整理) 常用快递公司列表 看看google员工的“堕落”工作环境 Eclipse的快捷键大全(不断更新中) [转]不花钱不求人 硬盘数据恢复六大招 [转]大学生不如狗 [转]dos常用命令 [转]net命令详解 [转]FTP命令大全 [转]如何在Web页面上直接打开、编辑、创建Office文档 鼠标指向提示javascript程序 Script直接写文件内容到word Asp.net中的两种刷新父窗体方法 [转]一个民工的月账本(看了让人流泪) 数据库连接串大全 【Asp.Net】在DataGrid里添加行脚本代码的方法 【Asp.Net】DataGrid里实现多选提交的方法 简单的SQL分页法
网页或VB中操作word的方法
柴火 · 2006-09-18 · via 博客园 - 柴火

这段代码给我帮了很大的忙,希望他能帮到更多的人!

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