2012-08-24 106 views
0

宏表和數據,我需要2個宏,這將幫助我完成我的工作速度快:在Word 2007/2010

  • 一個刪除所有從文件(不管的地方)的圖像。
  • 第二個將創建一個表並自動在其下插入數據。 (我必須將數千個doc文件合併在一起,並在每個插入文件的頂部創建該表)。這可以做到嗎?

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

所有文件開始使用此文字,只有什麼是星號是不同

,我必須創建一個表與行‘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ă ..." 

有人可以幫我用宏,將自動創建該表

+0

你可以用VBA做到這一點,但也不是沒有VBA知識...;)開始通過記錄你想要做什麼的宏。確保你看到了開發者標籤,然後點擊「錄製宏」按鈕。然後,您將完成創建所需表的步驟。單擊「停止錄製」後,可以在VBA編輯器(「Alt + F11」)中查看錄製的宏,並根據需要進行修改。如果您需要更多幫助,請發佈您嘗試過的代碼。 –

回答

0

這是不是真的很清楚你是什麼意思合併,究竟應該在表中。如果您想將多個文檔的內容合併爲一個「合併」doc文件,則下面是對第二個宏的快速且骯髒的解決方案:

請注意,在VBA編輯器的工具/參考下,您必須選中「微軟腳本運行時「在可用的庫下。

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