导航:首页 > 文件教程 > 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相关的资料

热点内容
小米5splus微信运动 浏览:813
热血战斗小说去哪个网站 浏览:281
小孩学哪个编程语言好 浏览:279
网站参数筛选怎么做 浏览:627
幼儿编程有什么问题 浏览:693
工商银行app人工服务在哪里 浏览:19
怎么让文件中全体内容往下移 浏览:783
魔兽争霸126版本转换器 浏览:984
word2003精简版下载 浏览:703
微博跳转appstore 浏览:537
打开文件时权限a代表什么 浏览:155
昆仑通态导出数据文件名 浏览:338
手机迁移数据为什么需要重新登录 浏览:958
录入数据库的图片如何更改 浏览:132
怎样获取邮箱帐号和密码 浏览:809
怎么通过js实现回到指定页面 浏览:140
如何用网络签字 浏览:552
三星电视拆机教程 浏览:19
创维怎么连接网络 浏览:868
2007版word绘图在哪里 浏览:311

友情链接