怎么用COM读写WORD里的文本信息?
1.你说的这个主要是取得word接口 然后配合word自带的宏完成任务 实现起来很简单COleVariant vTrue((short)TRUE), vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);_Application m_App;//定义Word提供的应用程序对象;Documents m_Docs;//定义Word提供的文档对象;Selection m_Sel;//定义Word提供的选择对象;m_Docs.ReleaseDispatch();m_Sel.ReleaseDispatch();m_App.m_bAutoRelease=true;if(!m_App.CreateDispatch("Word.Application")){ AfxMessageBox("创建WordXP服务失败!"); exit(1); }//下面是定义VARIANT变量;COleVariant varFilePath(sPath+"MYDOC.DOC");COleVariant varstrNull("");COleVariant varZero((short)0);COleVariant varTrue(short(1),VT_BOOL);COleVariant varFalse(short(0),VT_BOOL);m_Docs.AttachDispatch(m_App.GetDocuments());//将Documents类对象m_Docs和Idispatch接口关联起来;m_Docs.Open(varFilePath,varFalse,varFalse,varFalse,varstrNull,varstrNull,varFalse,varstrNull,varstrNull,varTrue,varTrue,varTrue,varTrue,varTrue,varTrue);//打开Word文档; m_Sel.AttachDispatch(m_App.GetSelection());//将Selection类对象m_Sel和Idispatch接口关联起来;下面就是操作了~2.用批处理做不到 如果只是这样子的话 连VC都可以省了 VBS 就能做到比如新建一个c:\1.doc 里面写上wangtk1982 然后保存退出 编辑下面文件为vbs文件 运行看看结果Dim oWordSet oWord = WScript.CreateObject("Word.Application")set myDoc =oWord.Documents.Open("c:\1.doc")With oWord.Selection.Find.Text = "1982".Replacement.Text = "2011".Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = True.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd WithoWord.Selection.Find.Execute ,,,,,,,,,,1myDOc.SavemyDoc.Closeoword.Quit
vb 打开word 保存后 第二次打开出现问题
第一次启动了word服务,没有关闭:这些:mydocument.closeset mydocument= nothingset myword =nothing改成:mydocument.Closemyword.Documents.Savemyword.QuitSet mydocument = NothingSet myword = Nothing再把Selection改成myword.Selection,ActiveDocument也要改成mydocument,你上面mydocument要指定,ChangeFileOpenDirectory不要用!Dim myword As New word.ApplicationDim mydocument As word.Document'On Error Resume NextSet myword = CreateObject("word.application")Set mydocument = myword.Documents.Open(App.Path & "\模板.doc")myword.Visible = Truemyword.Selection.MoveRight Unit:=wdCell' myword.Selection.TypeText Text:=Text5.Textmyword.Selection.MoveRight Unit:=wdCell' myword.Selection.TypeText Text:=Text6.Text'ChangeFileOpenDirectory "C:\Documents and Settings\Administrator\桌面\"mydocument.SaveAs FileName:="C:\Documents and Settings\Administrator\桌面\文电.doc", FileFormat:=wdFormatDocument, _LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _Falsemydocument.Closemyword.Documents.Savemyword.QuitSet mydocument = NothingSet myword = NothingShell "cmd /c start """" " & """C:\Documents and Settings\Administrator\桌面\文电.doc""", vbHide
请问怎么将PPT文件转成word格式?(求助)
应用程序完美转换PPT 到Word 文档 说起来很简单,就是你把下面这段代码文字复制到Windows 文本中,将文件保存为 .vbs生成一个可执行程序。
保存在任何一个地方,比如桌面。
这段代码也是我在无意中发现的,但使用后感觉已经很好,并且简单。
'绑定到本地计算机 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 怎样使用程序将PPT转换为Word 文档? 将你需要转换的PPT文档放到C:\ 的根目录下,双击我们刚才生成的 .vbs 程序,弹出下面的对话框,点击“确定”。
之后稍等片刻(根据PPT 文档的大小可能等待的时间有所区别)。
就会自动打开一个已经生成的Word 文档,怎么样,你看到了什么?转换完成,弹出下面的对话框,点击确定后收工。
这个程序无需安装,直接运行,文件也小。
在转换前最好将之前打开的Word 和PowerPoint程序关闭。
由于本程序转换后的Word文档中文字顺序并未排版,因此尚需用户自行调整。
但是这已经让我们事半功倍了。
为什么"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
ppt文件怎么转换成word文件
PowerPoint 20031 运行PowerPoint 2003软件,单击菜单栏的“文件”按钮,打开的快捷菜单指向“发送”,在下一级菜单中单击“Microsoft Office Word”命令2 弹出“发送到 Microsoft Office Word”对话框,选择您喜欢的版式界面,然后在“将幻灯片添加到 Microsoft Office Word 文档”中一栏选择“粘贴”或“粘贴链接”方式 END PowerPoint 20101 运行PowerPoint 2010软件,单击左上角的“文件”按钮,出来的界面单击左侧的“保存并发送”选项2 在文件类型栏下单击“创建讲义”,然后在右侧界面中单击“创建讲义”按钮3 弹出跟PowerPoint 2003一样的界面,设置完成后单击“确定”按钮即可 END 使用脚本文件把PPT转换为Word 文档 在桌面上新建一个文本文档,将下面的代码复制进去'绑定到本地计算机 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 在菜单栏点击“文件”——“另存为”命令 指定好要保存文件的位置,在文件名框中输入任意名称+vbs扩展名,然后单击“保存”按钮 此时会在桌面上生成vbs脚本文件,将要转换的PPT演示文稿放到C盘根目录,并执行vbs脚本文件 弹出以下提示对话框,直接单击“确定”按钮即可6 最后自动打开转换好的Word 文档并弹出以下提示对话框,单击“确定”按钮
VB 怎么按页拆分word文档?
下面是按页拆分word文档的程序,请参考:Option Explicit Dim oWord As Word.Application Dim oDoc As Word.Document Dim oNewDoc As Word.Document Dim oRange As Word.Range Dim iPageNumber As Integer Dim iCount As Integer Dim strTestDir As String Dim strTestFile As String Private Sub Command1_Click() Command1.Visible = False Dim lCurrentStart As Long Dim lCurrentEnd As Long Dim lDocumentEnd As Long Dim lOutputCount As Long lOutputCount = 0 'Launch Word and make it visible Set oWord = CreateObject("Word.Application") oWord.Visible = True 'Open the test document Set oDoc = oWord.Documents.Open(FileName:="C:\ThreePageDocument.doc") 'Find the beginning end of the document oDoc.Select lCurrentStart = oWord.Selection.Start lCurrentEnd = lCurrentStart lDocumentEnd = oWord.Selection.End 'Move the insertion point to the beginning of the document oWord.Selection.Collapse wdCollapseStart Do While (lCurrentEnd 'Move the insertion pointer to the bottom of this page oWord.Browser.Target = wdBrowsePage oWord.Browser.Next lCurrentEnd = oWord.Selection.End 'On the last page, the start and end will be the same If (lCurrentStart = lCurrentEnd) Then lCurrentEnd = lDocumentEnd End If 'Capture the Range of the current page Set oRange = oDoc.Range(lCurrentStart, lCurrentEnd) 'Create a new document and copy the range to it Set oNewDoc = oWord.Documents.Add oRange.Copy oNewDoc.Range(0, 0).Paste 'Release the Range so we don't leak references Set oRange = Nothing 'Save the new document and close it oNewDoc.SaveAs FileName:="C:\Result" & lOutputCount & ".doc" ' You can save as another FileFormat. If so, change the ' file extension accordingly. oNewDoc.Close Set oNewDoc = Nothing 'Increment the output counter so we don't overwrite this file later lOutputCount = lOutputCount + 1 'Reset the current start position lCurrentStart = oWord.Selection.End Loop End Sub
wordvba取几个数中的最小值?dima%,b%,c%Selection.TypeTextText:...
1、新建Excel工作簿,在工作表中依次输入文件夹内的Word文件名。
2、打开文件夹,按下shift键右键单击文件,找到复制为路径命令,并单击。
3、依次复制文件的路径到Excel工作簿内,和相应的文件名相对应。
4、在C列使用HYPERLINK函数创建链接,公式为:=HYPERLINK(B2,"打开"&A2)5、公式解析:HYPERLINK函数是用来创建超链接的函数,第一参数是打开文件的路径,第二个参数的意思是超链接显示的名称。
经过如此设置,就能为多个Word文件创建索引目录,即使不在同一个文件夹也适用于这个方法。
6、使用这个方法也是有效的提高效率,对文件的归纳整理很有帮助。
vc搜索word和pdf文档,可否加入算法
#include "stdafx.h"#pragma warning(disable:4259)#import "C:\\Program Files\\Common Files\\Microsoft Shared\\Office11\\MSO.DLL" rename("IAccessible", "msoIAccessible")using namespace Office;#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB"//using namespace VBIDE; #import "d:\\Program Files\\Microsoft Office\\OFFICE11\\MSWORD.OLB" rename("ExitWindows","WordExitWindows")using namespace Word;#include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){CoInitialize(0);{_ApplicationPtr m_WordPtr;DocumentsPtr m_DocsPtr;_DocumentPtr m_DocPtr;HRESULT hr;try{//CLSID sid;//CLSIDFromProgID(L"word.application",&sid);hr=m_WordPtr.CreateInstance(__uuidof(Application)); m_WordPtr->put_Visible(VARIANT_TRUE);m_DocPtr=m_WordPtr->Documents->Add();LPSTR a = "c:\\22.doc";CComBSTR b = a;BSTR c = b.m_str;VARIANT va;va.vt = VT_BSTR;va.bstrVal = c;m_WordPtr->Documents->Open(&va);SelectionPtr sel=m_WordPtr->GetSelection();sel->TypeText(_bstr_t("sadsaS12as"));sel->MoveEnd();InlineShapePtr sh=sel->GetInlineShapes()->AddPicture(_bstr_t("c:\\1.jpg"));sel->SetRange(1,2);//sel->TypeText(_bstr_t("!!!!!!!"));_bstr_t text=sel->GetText();char *s=_com_util::ConvertBSTRToString(text);coutTablesPtr tables = sel->GetTables();TablePtr table = tables->Add(sel->GetRange(), 2, 5);BordersPtr bords = table->GetBorders();bords->PutOutsideLineStyle(wdLineStyleSingle);bords->PutOutsideLineWidth(wdLineWidth150pt);bords->PutInsideLineStyle(wdLineStyleSingle);for (int i = 1; i{for (int j = 1; j{table->Cell(i,j)->GetRange()->PutText("20");}}
WORD中的宏是怎么用一些基本的功能怎么用,一般都用他做什么?
一、宏的录制 在这里举一实例。
例如,在Word 97中,要插入字符,则往往要到符号框中查找半天。
对于一些常用的符号,如“¥”,便可以使用宏来使工作简化。
1.单击“工具”选单中“宏”子选单,再单击“录制新宏”选项。
2.给宏取名为“Yuan”,再单击“键盘”。
3.在弹出的对话框中指定快捷键,可指定为“Ctrl+Y”,再关闭该对话框回到“录制宏”对话框。
单击“确定”按钮启动记录器。
4.运行“插入”选单中的“符号”子选单,从弹出的“符号”框中选择“¥”,插入后再关闭。
另外,也可以指定到工具栏,从弹出的“自定义”对话框中的“命令”栏中把“Normal.NewMacro1.Yuan”拖放到工具栏中。
5.单击“停止录制”工具栏中的“停止录制”按钮。
6.单击“工具”选单中“宏”子选单,再单击“宏”命令。
7.选择第二步中的宏名称,再单击“编辑”按钮。
这时我们可以从中看到以下代码: Sub Yuan() Selection.InsertSymbol Font:=〃楷体—GB2312〃,CharacterNumber:=-27,Unicode:=True End Sub 以后,当你需要插入字符“¥”时,只需按下快捷键“Ctrl+Y”,或者是在工具栏点击“Normal.NewMacrol.Yuan”便可以了。
二、宏的编辑 宏录制器将以上宏操作翻译为Visual Basic代码。
但是,录制宏时会受到一些限制。
许多复杂的宏,例如,要用到循环语句,便无法录制。
为了提高录制的宏的功能,就可能需要修改录制到模块中的代码。
具体操作为:单击“工具”选单中“宏”子选单,再单击“宏”命令。
选择第二步中的宏名称,再单击“编辑”按钮。
然后便加载Visual Basic编辑器,我们可以看到所录制的宏自动生成的Visual Basic代码。
例如,在C:\My Document中有200个Word文档,依次命名为“1.doc”,“2.doc”,“3.doc”,…“200.doc”,我们需要把文件格式改变为文本文件,即txt文件。
先以1.doc为例,录制一个宏,打开文档,另存为txt文件,再关闭该活动文档。
生成的Visual Basic代码如下: Sub Macro1() ChangeFileOpenDirectory 〃C:\My document〃 Documents.Open FileName:=〃1.doc〃 ActiveDocument.SaveAs FileName:=〃1.txt〃,FileFormat:=wdFormatText ActiveWindow.Close End Sub 下一步便进行编辑,用一个循环语句依次打开各个文件,转化后再关闭。
代码如下: Sub Macro1() dim i for i=1 to 200 ChangeFileOpenDirectory 〃C:\My document〃 Documents.Open FileName:=i & 〃.doc〃 ActiveDocument.SaveAs FileName: =i & 〃.txt〃, FileFormat:=wdFormatText ActiveWindow.Close next i End Sub 再次运行该宏,便可以轻松完成任务。
宏的作用由此可略见一斑。
转载请注明出处51数据库 » c word selection
熙沫女神