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

熱點內容
pe模式桌面文件在哪 瀏覽:641
文件領導簽字在哪裡 瀏覽:239
電腦保存文件是點哪裡 瀏覽:689
word07圖片框 瀏覽:359
跨境付app現在支持哪些國家 瀏覽:647
手機mid文件 瀏覽:929
華碩筆記本升級bios找不到文件 瀏覽:399
編程和電腦哪個更適合孩子 瀏覽:718
xls壓縮文件怎麼設置 瀏覽:423
微信眨眼小女孩 瀏覽:207
cad2010安裝文件 瀏覽:379
編程上什麼學 瀏覽:364
美版s7升級70移動4g 瀏覽:112
金融數據包含哪些 瀏覽:240
尼爾應用程序錯誤 瀏覽:157
淘特app如何助力 瀏覽:472
cad文件有木馬 瀏覽:459
多頁文件怎樣改變字體 瀏覽:145
16燈搖搖棒的程序 瀏覽:705
作業成本相關數據哪裡找 瀏覽:826

友情鏈接