表和数据的宏在词2007/2010

时间:2012-08-24 07:13:58

标签: ms-word word-vba

我需要2个宏来帮助我更快地完成工作:

  • 一个删除文档中的所有图像(无论在哪里)。
  • 第二个将创建表并自动在其下插入数据的表。 (我必须将数千个doc文件组合在一起,并在每个插入文件的顶部创建此表)。可以这样做吗?

实施例。

"R O M Â N I A
ÎNALTA CURTE DE CASAŢIE ŞI JUSTIŢIE
SECŢIA CIVILĂ ŞI DE PROPRIETATE INTELECTUALĂ **(this is aligned at left or centered, and always has 2 enters after it for inserting the table, only this line may be different but the first to are always the same)**


 Decizia nr. **2570** Dosar nr. **9304/1/2009**
 Şedinţa publică ..." 

所有文件都以此文字开头,只有与asterix不同的文件

我必须使用“Decizie”,“Dosar”和数字为该行创建一个表格 像这样的东西:

"R O M Â N I A
ÎNALTA CURTE DE CASAŢIE ŞI JUSTIŢIE
SECŢIA CIVILĂ ŞI DE PROPRIETATE INTELECTUALĂ

 |Decizia nr. *2570/**2009***                        |                Dosar nr. *9304/1/2009*|  - a table without borders, first column aligned left, second one right, at the first column also added the date from the second one 

 Şedinţa publică ..."

有人可以帮助我自动创建此表的宏吗?

1 个答案:

答案 0 :(得分:0)

通过组合以及表格中究竟应该是什么来表达你的意思并不是很清楚。如果你想在一个“组合”的doc文件中包含许多文档的内容,那么这里是第二个宏的快速而肮脏的解决方案:

请注意,在VBA编辑器的工具/参考中,您必须在可用库下检查“Microsoft Scripting Runtime”。

Dim fs As New FileSystemObject
Dim fo As Folder
Dim fi As File

Sub processDocFiles()
    Dim doc As Document
    Dim thisdoc As Document

    Set thisdoc = ActiveDocument
    ' set the directory
    Set fo = fs.GetFolder("C:\Temp\doc")

    ' iterate through the files
    For Each fi In fo.Files
        ' check the files
        If (fi.Name <> ActiveDocument.Name) And (Left(fi.Name, 1) <> "~") And (Right(fi.Name, 5) = ".docx") Then
            Debug.Print "Processing " & fi.Name
            Set doc = Application.Documents.Open(fi.Path)
            ' doc.Content.InsertAfter (fi.Path)

            thisdoc.Content.InsertAfter (doc.Content)
            thisdoc.Content.InsertAfter ("--------------------------------------------------" & Chr(13) & Chr(10))
            doc.Close
        End If
    Next

End Sub

这会将文件夹中所有doc文件的内容复制到一个文档中。 另一个是:

Sub delImages()
    Dim doc As Document
    Dim thisdoc As Document

    Set thisdoc = ActiveDocument
    ' set the directory
    Set fo = fs.GetFolder("C:\Temp\doc")

    ' iterate through the files
    For Each fi In fo.Files
        ' check the files
        If (fi.Name <> ActiveDocument.Name) And (Left(fi.Name, 1) <> "~") And (Right(fi.Name, 5) = ".docx") Then
            Debug.Print "Processing " & fi.Name
            Set doc = Application.Documents.Open(fi.Path)
            For Each pic In doc.InlineShapes
                pic.Delete
            Next
            doc.Save
            doc.Close
        End If
    Next

End Sub