vbs修改word内容

BuildVersion = "WScript.BuildVersion:"+CStr(WScript.BuildVersion)+chr(10)
FullName = "WScript.FullName:"+WScript.FullName+chr(10) 
Interactive = "WScript.Interactive:"+CStr(WScript.Interactive)+chr(10)
Name = "WScript.Name:"+CStr(WScript.Name)+chr(10)   
Path = "WScript.Path:"+WScript.Path+chr(10)  
ScriptFullName = "WScript.ScriptFullName:"+WScript.ScriptFullName+chr(10)
ScriptName = "WScript.ScriptName:"+WScript.ScriptName+chr(10)
Version = "WScript.Version:"+WScript.Version+chr(10)
Timeout = "WScript.Timeout:"+CStr(WScript.Timeout)+chr(10)
Arguments=""


For I = 0 to WScript.Arguments.Count - 1
Arguments = Arguments + "Arguments"+CStr(I)+":"+WScript.Arguments(I)+chr(10)
Next
'MsgBox BuildVersion+FullName+Interactive+Name+ScriptFullName+ScriptName+Version+Timeout+Arguments



For I = 0 to WScript.Arguments.Count - 1
DocPathName = WScript.Arguments(I)
Call ProcessWord(DocPathName)
Next

Private  Function GetHeader(str,line)
	GetHeader = ""
	l = len(str)
	if l > 0 then
	   for k=1 to len(str) 
			ch = mid(str,k,1)
			if line= 84 then
				MsgBox(str &"" &ch)
			end if
			if IsNumeric(ch) or ch = "."  then	
				GetHeader = Mid(str,1,k)
			else 
				Exit For
			end if
		next

	end if
					
End Function

Private Function GetHeaderLever(str)
	level=1
	for h=1 to len(str)
		if mid(str,h,1) = "." then
			level = level +1
		end if
	next	
	GetHeaderLever = level
end Function

Private Function SetStyle(p,level,file)

	if level = 1 then
		p.Range.Font.Size = 30
		'p.Range.Font.Name = "??"	
		p.Range.Font.Bold  = FALSE
		p.Range.Font.Italic   = TRUE	
		p.SpaceAfter  =0
		p.SpaceBefore =0
	elseif  level = 2 then
		p.Range.Font.Size = 20
		'P.Range.Font.ColorIndex   = 1
		P.Space2
		p.LineUnitBefore  =0
		p.LineUnitAfter =0
		'P.IndentCharWidth(4)
		'P.IndentFirstLineCharWidth(2)
	elseif level = 3 then
		p.Range.Font.Size = 10
		P.Space15 
	end if
	file.WriteLine(level)
end Function


Private Function ProcessWord(DocPathName)
	if Right(DocPathName,4) <> ".doc" and Right(DocPathName,5) <>".docx" then
		MsgBox "NO word"
	end if
	
	 Set fso = CreateObject("Scripting.FileSystemObject")
	 set file = fso.CreateTextFile ("C:\test.txt",true)
	 file.WriteLine("abdfdfc")
	
	Set objWord = CreateObject("Word.Application")
	objWord.Visible = true 
	
	Set Document = objWord.Documents.Open(DocPathName)
	for i=1 to Document.Paragraphs.Count
		t1 = Document.Paragraphs(i).Range.Text
		t=  Document.Paragraphs(i).Range.ListFormat.ListString 
		tt = GetHeader(t,i)

		if len(tt) >0 then
			call SetStyle(Document.Paragraphs(i),GetHeaderLever(tt),file)
		end if		
			file.WriteLine(i &" " & tt & "==(" & GetHeaderLever(tt)&")"& t)
	
	next
	
	file.Close()
	'Document.Close
	

End Function
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

站长漫谈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值