0

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

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

前任。

"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ă ..."

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

4

1 回答 1

0

目前还不清楚你所说的组合是什么意思,表中应该包含什么。如果您想在一个“组合”文档文件中包含多个文档的内容,那么这是第二个宏的快速而肮脏的解决方案:

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

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
于 2012-08-24T09:30:42.667 回答