word vbs setheight setheightinpoints
- 作者: 日骆希珊
- 来源: 51数据库
- 2020-04-15
电脑中了VBS病毒,我的电脑图标,文本文档,Word全
代码是vbs代码,保存到任意位置使用:'═════代═══码═══开═══始═════set fso=CreateObject("Scripting.FileSystemObject")set oWord=CreateObject("word.application")oWord.Visible = Falseset fs=fso.getfolder("c:\123").filesfor each f in fsext=lcase(right(f.name,4))if ext="docx" or ext=".doc" thenmnm=fso.GetParentFolderName(f.path)&"\"&fso.getbasename(f.path)oWord.Documents.Open f.pathoWord.ActiveDocument.SaveAs2 mnm&".txt",2oWord.ActiveDocument.closeend ifnextoWord.quitmsgbox "执行完毕!"'Created By escortmnm from VBS团队'═════代═══码═══结═══束═════
vbs中怎样用规定软件打开文件如用word打开txt文本的脚本
Option ExplicitDim WSshellSet WSshell=CreateObject("WScript.Shell")WSshell.Run """F:小工具Notepad otepad .exe"" ""ip.txt"""'""F:小工具Notepad otepad .exe""替换成word的完全路劲即可'语法格式:"""软件的完全路径"" ""文件的完全路劲"""
vbs如何实现:输出所有已经打开的窗口
先分析一下你的语句:"输出xx的窗口"——这到底什么意思呢?输出到哪? vbs:Set objWord = CreateObject("Word.Application") objword.Visible=falseSet colTasks = objWord.Tasks For Each objTask in colTasks If objTask.Visible Then Wscript.Echo objTask.Name End If Next objWord.Quit
用vbs打开程序
pro="c:\windows\system32\notepad.exe"'要打开的程序,写完整路径n=split(pro,"\")name=n(ubound(n))for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_ s=s&sep&ps.name:sep="|":nexts=split(s,"|")for i=0 to ubound(s)if name=s(i) then wscript.quitnextcreateobject("wscript.shell").run pro
vbs如何检测当前是否有标题为“XXXXX”的窗口
on error resume nexttitle="Form1" '窗口标题Set ws = CreateObject("wscript.shell")Set objWord = CreateObject("Word.Application")Set colTasks = objWord.Tasksdo Set colTasks = objWord.Tasksif colTasks.exists("Form1") then msgbox "窗口存在"ws.run "tskill winword",0 '或者 objword.quitwscript.quitend ifwscript.sleep 1000loop
电脑中了vbs.auotrun.cz病毒,用360杀了以后把word文档全部隔离了。
...
可以用脚本来做。
1、用记事本新建一个文本文件,把它保存为“批量重命名.vbs”(注意不要弄成了“批量重命名.vbs.txt”,也就是要确保其扩展名为“.vbs”);2、把下列代码粘贴到这个VBS文件中:Option Explicit Const g_strRootPath = "c:\Temp\docs\Word\ToRename\" ' 指定存放所有文件的目录,可以有子目录 Const g_nTitleMaxLen = 16 ' 指定获取文档里面第一段中的前多少个字符来作为文件名 Call Main' 主函数入口 Sub Main() Dim fso, oFolder, oWordApp Set oWordApp = CreateObject("Word.Application") Set fso = CreateObject("Scripting.FileSystemObject") Set oFolder = fso.GetFolder(g_strRootPath) RenameDocFilesUnderFolder oWordApp, fso, oFolder oWordApp.Quit Set oWordApp = Nothing MsgBox "完成!" End Sub' 重命名指定文件夹(递归)下面的所有Word文件,按照文件里面的第一句可见的文字命名 Sub RenameDocFilesUnderFolder(oWordApp, fso, oFolder) Dim oSubFolder, oFile, oDoc Dim strTitle, strFileName For Each oSubFolder In oFolder.SubFolders RenameDocFilesUnderFolder oWordApp, fso, oSubFolder Next For Each oFile In oFolder.Files Set oDoc = oWordApp.Documents.Open(oFile.Path) strTitle = GetFirstVisibleTextContent(oDoc) oDoc.Close Set oDoc = Nothing If Len(strTitle) 0 Then strFileName = fso.BuildPath(fso.GetParentFolderName(oFile.Path), strTitle & "." & fso.GetExtensionName(oFile.Path)) strFileName = GetUniqueFileName(fso, strFileName) fso.MoveFile oFile.Path, strFileName End If Next End Sub' 获取指定文档第一行可见文字 Function GetFirstVisibleTextContent(oDoc) Dim oParagraph Dim strContent For Each oParagraph In oDoc.Paragraphs strContent = GetSafeFileName(oParagraph.Range.Text) If Len(strContent) 0 Then GetFirstVisibleTextContent = strContent Exit Function End If Next GetFirstVisibleTextContent = "" End Function' 过滤文件名里面的无效字符 Function GetSafeFileName(strFileName) Dim arrUnsafeCharacters, strUnsafeChar Dim nIndex arrUnsafeCharacters = Array("\", "/", ":", "*", "?", """", "", "|") For nIndex = 0 To &H2F strFileName = Replace(strFileName, Chr(nIndex), "") Next For Each strUnsafeChar In arrUnsafeCharacters strFileName = Replace(strFileName, strUnsafeChar, "") Next GetSafeFileName = Left(Trim(strFileName), g_nTitleMaxLen) End Function' 获取不重复的文件名,如果有重名则在文件名后面附加“_1”、“_2”…… Function GetUniqueFileName(fso, strFullName) Dim strParentFolder, strBaseName, strExtensionName Dim nIndex If Not fso.FileExists(strFullName) Then GetUniqueFileName = strFullName Exit Function End If strParentFolder = fso.GetParentFolderName(strFullName) strBaseName = fso.GetBaseName(strFullName) strExtensionName = fso.GetExtensionName(strFullName) nIndex = 0 While fso.FileExists(strFullName) nIndex = nIndex + 1 strFullName = fso.BuildPath(strParentFolder, strBaseName & "_" & nIndex & "." & strExtensionName) Wend GetUniqueFileName = strFullName End Function3、修改代码中开始部分的两个设置,即:存放等待重命名的Word文件的根目录,以及获取文档第一段内容时最多保留多少个字符。
4、保存这个VBS文件,在资源管理器中双击运行它,直到看见“完成”!5、检查所有文件是否已自动重命名。
注意:如果有两个以上的文档依据其内容提取出来的文字相同,则会自动在文件名后面附加“_1”、“_2”、“_3”……。
如果有什么问题,请和我联系。
为什么"PPT文本转换器"只能将PPT的三页转换成WORD?
程序有问题。
请将下列内容复制到记事本里面,并保存为:PPT转WORD.vbs 然后将要转换的PPT和这个程序文件复制到C盘根目录下,双击这个程序文件运行即可在C盘根目录下自动生成一个WORD文件,内容就是PPT的内容。
'绑定到本地计算机 strComputer = "."'如果发生错误,继续执行 on error resume next Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") msgbox "此脚本可以批量将ppt文件中的文本转换为word文件。
图片、表格等内容则自动跳过" & vbcrlf & "使用时请把所有要转换的ppt文件复制到目录c:\下。
双击运行此文件即可。
" & vbcrlf & "运行此脚本需要本机上安装了office" '创建一个word对象 Set objWord = CreateObject("Word.Application")'创建一个ppt对象 Set pptApp = CreateObject("PowerPoint.application")'获得c:\目录下的文件集合 Set FileList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='c:'} Where " _ & "ResultClass = CIM_DataFile") For Each objFile In FileList'如果文件的扩展名是ppt If objFile.Extension = "ppt" Then pptApp.visible = true'打开这个ppt文件 Set pptSelection = pptApp.Presentations.Open("c:\" & objFile.FileName & "." & objFile.Extension)'如果想让脚本处理得快些,把下面一行改为“objWord.Visible = false”,不推荐。
objWord.Visible = true'新建一个word,以保存ppt中的文本 Set objDoc = objWord.Documents.Add() Set objSelection = objWord.Selection'从ppt的第一页开始循环。
Slides.Count即幻灯片的数量 For i = 1 To pptSelection.Slides.Count'从每一张ppt的第一个文本框开始循环,Shapes.Count,即每张幻灯片中文本框的数量 For j = 1 To pptSelection.Slides(i).Shapes.Count '如果是每页的第一行,就按标题处理,变成黑体字 if i =1 then objSelection.Font.Name = "黑体" '把文本框中的文字添加到word中 objSelection.TypeText pptSelection.Slides(i).Shapes(j).TextFrame.TextRange.text objSelection.TypeParagraph() objSelection.Font.Name = "宋体" end if objSelection.TypeText pptSelection.Slides(i).Shapes(j).TextFrame.TextRange.text '加一个回车 objSelection.TypeText vbcrlf Next next'关闭这个ppt文件 pptSelection.close'保存word文件。
objDoc.SaveAs("c:\" & objFile.FileName & ".doc")'如果不需要关闭word,把下面这一行删掉 objDoc.close'如果不想弹出消息框,把下面这一行删掉 msgbox "转换后的word已保存在c:\" & objFile.FileName & ".doc" else '没有ppt文件'msgbox "错误:c:\下没有发现ppt文件!" End If Next pptApp.quit
转载请注明出处51数据库 » word vbs setheight
