0

I need 2 macros that will help me to finish my work faster:

  • 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). 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"

and i have to create a table for the row with "Decizie", "Dosar" and numbers something like this:

"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?

1
  • You can do it with VBA, but not without VBA-knowledge... ;) Start by recording a macro of what you want to do. Make sure you see the developer tab and click the Record macro button. Then you go through the steps needed to create the tables that you need. After you click Stop recording you can view the recorded macro in the VBA editor (Alt+F11) and modify as needed. If you need further assistance, post the code you have tried. Aug 24, 2012 at 8:27

1 Answer 1

0

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.