如何将excel每次输入的数据,生成新的一份WORD文件(word文件是以表格形式反映)
简单的说,就是实现--excel与word文档的同步更新(但是要做到,能保证每次在excel里面输入后必须生成一个新的word文档)
哎···就是想偷懒。可惜不知道怎么弄 展开
1、在Word里面打开那个需要分割的文档(假设它的文件名叫做“原始文档.doc”);
2、键入ALT+F11打开VBA编辑器,选择菜单“插入-模块”;
3、粘贴下面的代码:
Option Explicit
Sub SplitPagesAsDocuments()
Dim oSrcDoc As Document, oNewDoc As Document
Dim strSrcName As String, strNewName As String
Dim oRange As Range
Dim nIndex As Integer
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set oSrcDoc = ActiveDocument
Set oRange = oSrcDoc.Content
oRange.Collapse wdCollapseStart
oRange.Select
For nIndex = 1 ToActiveDocument.Content.Information(wdNumberOfPagesInDocument)
oSrcDoc.Bookmarks("\page").Range.Copy
oSrcDoc.Windows(1).Activate
Application.Browser.Target = wdBrowsePage
Application.Browser.Next
strSrcName = oSrcDoc.FullName
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
Next
Set oNewDoc = Nothing
Set oRange = Nothing
Set oSrcDoc = Nothing
Set fso = Nothing
MsgBox "结束!"
End Sub
4、键入F5运行,看到“完成!”结束。
为什么非得要生成Word文档呀?表格的话,用excel不是挺好吗
2:当excel数据更改时,注意word中在可变数据中单击右键选择更新域此时word就会自动与excel同步变化