導航:首頁 > 文件教程 > 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相關的資料

熱點內容
哪些統計量可以反映數據波動 瀏覽:946
js地圖標記怎麼清空 瀏覽:479
googlenow教程 瀏覽:508
安全四個責任體系內容文件 瀏覽:965
南陽政務app怎麼注冊 瀏覽:343
照片壓縮包同一路徑的文件能刪嗎 瀏覽:590
路由沒網路怎麼辦 瀏覽:745
南京網站推廣大概多少錢 瀏覽:983
js隱藏列印出來 瀏覽:135
手工之家app哪裡下載 瀏覽:328
網路教育聯盟英語考試是什麼 瀏覽:69
macairwin10忘記密碼 瀏覽:716
java上傳方法 瀏覽:970
csc文件夾可以刪除嗎 瀏覽:130
打線工具怎麼用 瀏覽:376
mat文件如何轉換為cad 瀏覽:761
qq瀏覽器舊版本614 瀏覽:713
將資料庫文件批量導出excel 瀏覽:262
招投標文件在招標公司存多少年 瀏覽:551
u盤空間不足不能復制系統鏡像文件 瀏覽:212

友情鏈接