简体   繁体   English

word 2007/2010 中表格和数据的宏

[英]Macro for table and data in word 2007/2010

I need 2 macros that will help me to finish my work faster:我需要 2 个宏来帮助我更快地完成工作:

  • one to delete all the images from the document (no matter the place).一个从文档中删除所有图像(无论在哪里)。
  • a second one that will create a table and insert the data under it automatically.第二个将创建一个表并自动在其下插入数据。 (I have to combine in word thousands of doc files and create this table at the top of every inserted file). (我必须将数以千计的 doc 文件合并到 word 中,并在每个插入文件的顶部创建此表)。 Can this be done?这能做到吗?

Ex.前任。

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

all the files begin with this text, only what is with asterix is different "所有文件都以这个文本开头,只有 asterix 的内容不同

and i have to create a table for the row with "Decizie", "Dosar" and numbers something like this:我必须为带有“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ă ..."

Can somebody help me with a macro that will create this table automatically?有人可以帮助我使用一个可以自动创建此表的宏吗?

It is not really clear what do you mean by combining and what exactly should be in the table.您所说的组合是什么意思以及表格中究竟应该包含哪些内容并不清楚。 If you want to have the content of many docs in one, "combined" doc file, then here's a quick and dirty solution to the second macro:如果您想在一个“组合”文档文件中包含多个文档的内容,那么这里是第二个宏的快速而肮脏的解决方案:

Please note that under Tools / References in VBA editor you have to check "Microsoft Scripting Runtime" under available libraries.请注意,在 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

This copies the contents of all the doc files in a folder into one single document.这会将文件夹中所有文档文件的内容复制到一个文档中。 And the other one is:另一个是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM