【问题标题】:Macro for table and data in word 2007/2010word 2007/2010 中表格和数据的宏
【发布时间】:2020-07-06 16:32:40
【问题描述】:

我需要 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ă ..."

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

【问题讨论】:

  • 你可以用 VBA 来做,但不能没有 VBA 知识... ;) 首先记录你想做的事情的宏。确保您看到开发人员选项卡并单击Record macro 按钮。然后,您将完成创建所需表所需的步骤。单击Stop recording 后,您可以在VBA 编辑器(Alt+F11)中查看录制的宏并根据需要进行修改。如果您需要进一步的帮助,请发布您尝试过的代码。

标签: vba ms-word


【解决方案1】:

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

请注意,在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多