导航:首页 > 文件教程 > wordvbasplit

wordvbasplit

发布时间:2023-09-04 15:03:17

1. 如何用vba提取word单元格指定部分字段

假如有规律的话可用数组,相对简单一点,要不用INSTR查找,嗯,就烦了

第一,提取 :之前的字符
DIM s,arr
s="War_ID : SM3766R12-CA88770.9-23"
arr=split(s,":")
msgbox arr(0)

得到的是:分号前的字符串,
第二个 问题
Sub aaa()
Dim s, arr
s = "War_ID : SM3766R12-CA88770.9-23"
arr = Split(s, ":")
s = arr(1)
Set arr = Nothing
arr = Split(s, "-")
MsgBox arr(0)
End Sub

2. vba实现按特定的字符段落拆分word文档

下面代码把原文档按照指定的标识(这里是“END”)进行拆分。拆分之后的文档生成在源文档当前目录下,文件名后面附加“_1”、“_2”、“_3”等。

Option Explicit

Const Token = "END"

Sub SplitDocumentByToken()

Dim oNewDoc As Document
Dim strSrcName As String, strNewName As String
Dim nStart As Integer, nEnd As Integer, nIndex As Integer
Dim fContinue As Boolean
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

strSrcName = ActiveDocument.FullName

nIndex = 1
fContinue = True
Selection.StartOf WdUnits.wdStory

Do While fContinue
nStart = Selection.Start
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^13" & Token & "^13"
.Replacement.Text = ""
.Forward = True
.Wrap = WdFindWrap.wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
If Selection.Find.Execute Then
nEnd = Selection.End
Else
nEnd = ActiveDocument.Content.End
fContinue = False
End If
ActiveDocument.Range(nStart, nEnd).Copy
strNewName = fso.BuildPath(fso.GetParentFolderName(strSrcName), _
fso.GetBaseName(strSrcName) & "_" & nIndex & "." & fso.GetExtensionName(strSrcName))
Set oNewDoc = Documents.Add
Selection.Paste
oNewDoc.SaveAs strNewName
oNewDoc.Close False
nIndex = nIndex + 1
Selection.Collapse WdCollapseDirection.wdCollapseEnd
Loop

Set oNewDoc = Nothing
Set fso = Nothing

MsgBox "结束!"

End Sub

阅读全文

与wordvbasplit相关的资料

热点内容
压缩好的文件哪里找 浏览:831
百度网盘怎样上传文件夹 浏览:320
java发展是 浏览:892
程序编程结束还要做什么 浏览:778
pcb打版文件有哪些 浏览:39
网络原来ip地址忘记了怎么办 浏览:142
iphone6s微信密码设置 浏览:810
java将数字转换成字母 浏览:854
c盘中的哪些是系统文件夹 浏览:668
分布式服务如何跨库统计数据 浏览:829
力控转发数据客户端模式如何建立 浏览:200
怎么样让自己的网站不被别人看到 浏览:711
编程扩展效果如何 浏览:335
荣耀畅玩手环同步qq 浏览:475
怎么向sql中添加数据库 浏览:596
录歌失败重启app什么意思 浏览:522
压缩文件包怎么在微信发送 浏览:432
mysql数据库怎么插入时间值 浏览:191
微信视频不能转发朋友圈 浏览:596
影视后期的app有哪些 浏览:956

友情链接