worddoc.close word vba close - 电脑|办公 - 电脑办公-杀毒安全-网络-V3学习网
微商网
 
 
导航:首页 |电脑|办公|正文

worddoc.close word vba close

时间:2021-04-22 10:12:19
VB wordDoc Close 在一个工程里可以使用,而在另一个工程里出现 Sub 批量操作WORD() Dim path As String Dim FileName As String Di
作者:

VB wordDoc.Close 在一个工程里可以使用,而在另一个工程里出现...

Sub 批量操作WORD() Dim path As String Dim FileName As String Dim worddoc As Document Dim MyDir As String MyDir = "G:\360data\重要数据\桌面\新建文件夹 (2)" "文件夹路径根据需要自己修改,需要处理的文件都放该文件夹内 FileName = Dir(MyDir & "\*.doc*", vbNormal) Do Until FileName = "" If FileName ThisDocument.Name Then Set worddoc = Documents.Open(MyDir & "\" & FileName) worddoc.Activate Call 处理WORD "调用宏,换成你自己宏的名字 worddoc.Close True FileName = Dir() End If LoopSet worddoc = NothingEnd Sub"======================下面的宏换成你自己的宏=================================Sub 处理WORD() ActiveDocument.Paragraphs(1).Range.Select Selection.Font.Size = 72End Sub

vb 按下command1则打印指定路径的文件?

是什么文件呢?不同的文件打印方法不尽相同。

Private Sub Command1_Click()Dim WordApp As New Word.ApplicationWordApp.Visible = FalseWordApp.DisplayAlerts = wdAlertsNoneDim WordDoc As Word.DocumentSet WordApp = CreateObject("Word.Application")Set WordDoc = WordApp.Documents.Open("d:\test.DOC")WordDoc.PrintOut , , , , , , , 2 "#打印2份WordDoc.CloseWordApp.QuitSet WordApp = NothingEnd Sub

C#打印表单,表单包含标题,内容。

用word最好,代码是 using Word; 下面的例子中包括C#对Word文档的创建、插入表格、设置样式等操作:(例子中代码有些涉及数据信息部分被省略,重要是介绍一些C#操作word文档的方法) public string CreateWordFile(string CheckedInfo) ...{ string message = ""; try ...{ Object Nothing = System.Reflection.Missing.Value; Directory.CreateDirectory("C:/CNSI"); //创建文件所在目录 string name = "CNSI_" + DateTime.Now.ToShortString()+".doc"; object filename = "C://CNSI//" + name; //文件保存路径 //创建Word文档 Word.Application WordApp = new Word.ApplicationClass(); Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); //添加页眉 WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉内容]"); WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐 WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;//跳出页眉设置 WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距 //移动焦点并换行 object count = 14; object WdLine = Word.WdUnits.wdLine;//换一行; WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 WordApp.Selection.TypeParagraph();//插入段落 //文档中创建表格 Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 12, 3, ref Nothing, ref Nothing); //设置表格样式 newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleThickThinLargeGap; newTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle; newTable.Columns[1].Width = 100f; newTable.Columns[2].Width = 220f; newTable.Columns[3].Width = 105f; //填充表格内容 newTable.Cell(1, 1).Range.Text = "产品详细信息表"; newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体 //合并单元格 newTable.Cell(1, 1).Merge(newTable.Cell(1, 3)); WordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中 WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中 //填充表格内容 newTable.Cell(2, 1).Range.Text = "产品基本信息"; newTable.Cell(2, 1).Range.Font.Color = Word.WdColor.wdColorDarkBlue;//设置单元格内字体颜色 //合并单元格 newTable.Cell(2, 1).Merge(newTable.Cell(2, 3)); WordApp.Selection.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter; //填充表格内容 newTable.Cell(3, 1).Range.Text = "品牌名称:"; newTable.Cell(3, 2).Range.Text = BrandName; //纵向合并单元格 newTable.Cell(3, 3).Select();//选中一行 object moveUnit = Word.WdUnits.wdLine; object moveCount = 5; object moveExtend = Word.WdMovementType.wdExtend; WordApp.Selection.MoveDown(ref moveUnit, ref moveCount, ref moveExtend); WordApp.Selection.Cells.Merge(); //插入图片 string FileName = Picture;//图片所在路径 object LinkToFile = false; object SaveWithDocument = true; object Anchor = WordDoc.Application.Selection.Range; WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor); WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;//图片宽度 WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;//图片高度 //将图片设置为四周环绕型 Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape(); s.WrapFormat.Type = Word.WdWrapType.wdWrapSquare; newTable.Cell(12, 1).Range.Text = "产品特殊属性"; newTable.Cell(12, 1).Merge(newTable.Cell(12, 3)); //在表格中增加行 WordDoc.Content.Tables[1].Rows.Add(ref Nothing); WordDoc.Paragraphs.Last.Range.Text = "文档创建时间:" + DateTime.Now.ToString();//“落款” WordDoc.Paragraphs.Last.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; //文件保存 WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing); WordDoc.Close(ref Nothing, ref Nothing, ref Nothing); WordApp.Quit(ref Nothing, ref Nothing, ref Nothing); message=name+"文档生成成功,以保存到C:CNSI下"; } catch ...{ message = "文件导出异常!"; } return message; } 好好琢磨琢磨吧。

如何生成word文档的源码

/// public class WebForm1 : System.Web.UI.Page{protected System.Web.UI.WebControls.TextBox SaveAs;protected System.Web.UI.WebControls.Label Label2;protected System.Web.UI.WebControls.Label Label1;protected System.Web.UI.WebControls.Label result;protected System.Web.UI.WebControls.Button Button1;protected System.Web.UI.WebControls.TextBox wordText;private void Page_Load(object sender, System.EventArgs e){// 在此处放置用户代码以初始化页面}#region Web 窗体设计器生成的代码override protected void OnInit(EventArgs e){//// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

//InitializeComponent();base.OnInit(e);}/// /// 设计器支持所需的方法 - 不要使用代码编辑器修改/// 此方法的内容。

/// private void InitializeComponent(){this.Button1.Click += new System.EventHandler(this.Button1_Click);this.Load += new System.EventHandler(this.Page_Load);}#endregionprivate void Button1_Click(object sender, System.EventArgs e){Object Nothing=System.Reflection.Missing.Value;object filename=@SaveAs.Text;Word.Application WordApp=new Word.ApplicationClass();Word.Document WordDoc=WordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);Word.Table table=WordDoc.Tables.Add(WordApp.Selection.Range,1,1,ref Nothing,ref Nothing);table.Cell(1,1).Range.Text=wordText.Text;WordDoc.Paragraphs.Last.Range.Text="Wellcome To Aspxcn.Com";WordDoc.SaveAs(ref filename,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);result.Text="文档路径:"+SaveAs.Text+"(点击链接查看)生成结果:成功!";}}}在web.config中要设置权限。

怎么实现用vba 批量的搜索文档内容并收集到一张excel表里面

vba读取word内容会弄吗?dir(*.Doc)知道怎么用吗?大约思路吧1、枚举所有word文档2、查找word中的你需要的内容3、填写到excel表中呵呵,不知道你vba水平如何,但按你的题目,我也只能回答这么多了。

按这个思路百度去,总会找到办法的。

如何用java将pdf文件转换成word文件

需要用到插件jacob,自己去下载吧。

import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; import com.jacob.com.Variant; public class D2P { private ActiveXComponent wordCom = null; private Object wordDoc = null; private final Variant False = new Variant(false); private final Variant True = new Variant(true);/** *//** *//** *//*** 打开word文档** @param filePath* word文档* @return 返回word文档对象*/ public boolean openWord(String filePath) {//建立ActiveX部件 wordCom = new ActiveXComponent("Word.Application"); try {//返回wrdCom.Documents的Dispatch Dispatch wrdDocs = wordCom.getProperty("Documents").toDispatch();//调用wrdCom.Documents.Open方法打开指定的word文档,返回wordDoc wordDoc = Dispatch.invoke(wrdDocs, "Open", Dispatch.Method,new Object[] { filePath }, new int[1]).toDispatch(); return true; } catch (Exception ex) { ex.printStackTrace(); } return false; }/** *//** *//** *//*** 关闭word文档*/ public void closeWord() {//关闭word文件 wordCom.invoke("Quit", new Variant[] {}); }/** *//** *//** *//*** * 将word文档打印为PS文件后,使用Distiller将PS文件转换为PDF文件 *** @param sourceFilePath* 源文件路径 ** @param destinPSFilePath* 首先生成的PS文件路径 ** @param destinPDFFilePath* 生成PDF文件路径*/ public void docToPDF(String sourceFilePath, String destinPSFilePath,String destinPDFFilePath) { if (!openWord(sourceFilePath)) { closeWord(); return; }//建立Adobe Distiller的com对象 ActiveXComponent distiller = new ActiveXComponent("PDFDistiller.PDFDistiller.1"); try {//设置当前使用的打印机,我的Adobe Distiller打印机名字为"Adobe PDF" wordCom.setProperty("ActivePrinter", new Variant("MS Publisher Color Printer"));//设置printout的参数,将word文档打印为postscript文档。

目前只使用了前5个参数,如果要使用更多的话可以参考MSDN的office开发相关api//是否在后台运行 Variant Background = False;//是否追加打印 Variant Append = False;//打印所有文档 int wdPrintAllDocument = 0; Variant Range = new Variant(wdPrintAllDocument);//输出的postscript文件的路径 Variant OutputFileName = new Variant(destinPSFilePath); Dispatch.callN((Dispatch) wordDoc, "PrintOut", new Variant[] { Background, Append, Range, OutputFileName }); System.out.println("由word文档打印为ps文档成功!");//调用Distiller对象的FileToPDF方法所用的参数,详细内容参考Distiller Api手册//作为输入的ps文档路径 Variant inputPostScriptFilePath = new Variant(destinPSFilePath);//作为输出的pdf文档的路径 Variant outputPDFFilePath = new Variant(destinPDFFilePath);//定义FileToPDF方法要使用adobe pdf设置文件的路径,在这里没有赋值表示并不使用pdf配置文件 Variant PDFOption = new Variant("");//调用FileToPDF方法将ps文档转换为pdf文档 Dispatch.callN(distiller, "FileToPDF", new Variant[] { inputPostScriptFilePath, outputPDFFilePath, PDFOption }); System.out.println("由ps文档转换为pdf文档成功!"); } catch (Exception ex) { ex.printStackTrace(); } finally { closeWord(); wordCom=null;//释放在程序线程中引用的其它com,比如Adobe PDFDistiller ComThread.Release(); } } public static void main(String[] argv) { D2P d2p = new D2P(); d2p.docToPDF("d:/12.doc", "d:/1p.ps", "d:/1p.pdf");//这里是你建一个叫12.doc的word文档,生成的文档将在D盘下//1p.ps和1p.pdf(这是我们要的) } }

如何用VB将word文档已二进制的形式存Access数据库里 100jluwood ...

"题主可以参考下列示例代码:Private Sub Command0_Click()"注意代码需要先引用ADO类库2.5或以上版本Dim cn As New ADODB.Connection,strCn as StringDim rs As New ADODB.RecordsetDim strm As New ADODB.StreamstrCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyDB.mdb"cn.Open strCnrs.CursorLocation = adUseClient"打开ADO流对象With strm.Type = adTypeBinary "二进制模式.OpenEnd With"打开记录集rs.Open "[100jluwood]", cn, adOpenKeyset, adLockOptimistic "添加一条新记录,字段名是虚构的,请改为实际字段名rs.AddNewrs!F_id = "001"rs!F_Name = "MyWord"strm.LoadFromFile "C:\MyWord.doc" "读取Word文件rs!file = strm.Read "存入Word文件rs.Update "保存新增rs.CloseSet rs=Nothingcn.CloseSet cn=NothingEnd Sub

如何用java将pdf文件转换成word文件

new int[1]).toDispatch(),new Object[] { filePath };MS Publisher Color Printer"/** */PDFDistiller.PDFDistiller;/是否追加打印Variant Append = False.Documents的DispatchDispatch wrdDocs = wordCom.getProperty("Documents"//));/Adobe PDF"wordCom.setProperty("ActivePrinter&quot,返回wordDocwordDoc = Dispatch;/建立Adobe Distiller的com对象ActiveXComponent distiller = new ActiveXComponent("/作为输入的ps文档路径Variant inputPostScriptFilePath = new Variant(destinPSFilePath).Documents。

目前只使用了前5个参数, new Variant[] {Background, Append, Range;/*** * 将word文档打印为PS文件后,使用Distiller将PS文件转换为PDF文件 *** @param sourceFilePath* 源文件路径 ** @param destinPSFilePath* 首先生成的PS文件路径 ** @param destinPDFFilePath* 生成PDF文件路径*/.Variant;作为输出的pdf文档的路径Variant outputPDFFilePath = new Variant(destinPDFFilePath);//定义FileToPDF方法要使用adobe pdf设置文件的路径,在这里没有赋值表示并不使用pdf配置文件Variant PDFOption = new Variant("");//调用FileToPDF方法将ps文档转换为pdf文档Dispatch.callN(distiller, "FileToPDF", new Variant[] {inputPostScriptFilePath, outputPDFFilePath, PDFOption });System.out.println("由ps文档转换为pdf文档成功!");} catch (Exception ex) {ex.printStackTrace();} finally {closeWord();wordCom=null;//释放在程序线程中引用的其它com,比如Adobe PDFDistillerComThread.Release();}}public static void main(String[] argv) {D2P d2p = new D2P();d2p.docToPDF("d:/12.doc", "d:/1p.ps", "d:/1p.pdf");//这里是你建一个叫12.doc的word文档,生成的文档将在D盘下//1p.ps和1p.pdf(这是我们要的)}}.invoke(wrdDocs, &quot.invoke("Quit";设置当前使用的打印机,我的Adobe Distiller打印机名字为"/** */.1");try {///** */Open"public boolean openWord(String filePath) {///*** 关闭word文档*/public void closeWord() {///输出的postscript文件的路径Variant OutputFileName = new Variant(destinPSFilePath);public class D2P {private ActiveXComponent wordCom = null.jacob.Dispatch;import com, "PrintOut"需要用到插件jacob,自己去下载吧;//).println("打印所有文档int wdPrintAllDocument = 0;Variant Range = new Variant(wdPrintAllDocument);//*** 打开word文档** @param filePath* word文档* @return 返回word文档对象*//是否在后台运行Variant Background = False;/.out;/** *//** */import com.jacob.com.ComThread;import com。

import com.jacob.activeX.ActiveXComponent.Open方法打开指定的word文档, OutputFileName });System;Word.Application", new Variant("return true.toDispatch();//** */.com, new Variant[] {});}/** */Dispatch.callN((Dispatch) wordDoc.jacob,String destinPDFFilePath) {if (;由word文档打印为ps文档成功!");/public void docToPDF(String sourceFilePath, String destinPSFilePath;private Object wordDoc = null;/设置printout的参数,将word文档打印为postscript文档,如果要使用更多的话可以参考MSDN的office开发相关api/, Dispatch.Method,详细内容参考Distiller Api手册//返回wrdCom;private final Variant False = new Variant(false);private final Variant True = new Variant(true);建立ActiveX部件wordCom = new ActiveXComponent(&quot!openWord(sourceFilePath)) {closeWord();return;);关闭word文件wordCom;/调用Distiller对象的FileToPDF方法所用的参数;try {/} catch (Exception ex) {ex.printStackTrace();}return false;}/** *//调用wrdCom;/** */}/.com 展开

用JAVA编写一个GUI记事本程序,实现文本的输入,保存,修改,打开...

代码如下:import java.io.*;import java.awt.*;import java.awt.event.*;public class jtxtfm{public static void main(String args[]){jtxtfrm fm=new jtxtfrm();}}class jtxtfrm extends Frame implements ActionListener{FileDialog op,sv;Button btn1,btn2,btn3;TextArea tarea;jtxtfrm(){super("读写文件");setLayout(null);setBackground(Color.cyan);setSize(600,300);setVisible(true);btn1=new Button("打开");btn2=new Button("保存");btn3=new Button("关闭");tarea=new TextArea("");add(btn1);add(btn2);add(btn3);add(tarea);tarea.setBounds(30,50,460,220);btn1.setBounds(520,60,50,30);btn2.setBounds(520,120,50,30);btn3.setBounds(520,180,50,30);op=new FileDialog(this,"打开",FileDialog.LOAD);sv=new FileDialog(this,"保存",FileDialog.SAVE);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this); addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ setVisible(false); System.exit(0); } } );}public void actionPerformed(ActionEvent e){if(e.getSource()==btn1){String str;op.setVisible(true);try{File f1=new File(op.getDirectory(),op.getFile());FileReader fr=new FileReader(f1);BufferedReader br=new BufferedReader(fr);tarea.setText("");while((str=br.readLine())!=null)tarea.append(str+"\n");fr.close();}catch(Exception e1){}}if(e.getSource()==btn2){sv.setVisible(true);try{File f1=new File(sv.getDirectory(),sv.getFile());FileWriter fw=new FileWriter(f1);BufferedWriter bw=new BufferedWriter(fw);String gt=tarea.getText();bw.write(gt,0,gt.length());bw.flush();fw.close();}catch ( Exception e2){}}if(e.getSource()==btn3){System.exit(0);}}}效果图:

大家还关注
    
阅读排行
推荐阅读