|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Macro to check the existence of a word docx file and create a new word file with specific content.
Hi guys!
I have this macro: Code:
Sub Rename_Folder() Dim oFSO As Object Dim oFolder As Object Dim oSubFolder As Object Dim i As Integer Dim strPath As String Dim strSubFolderPath As String Dim strSubFolderNewName As String Dim fisword As String Dim FOLDER As String Dim primit As String Dim cinci As String Dim cinci1 As String Dim raport As String Dim BAAR As String Dim nr As String Dim marca As String Dim data As String Dim anexa1 As String Dim anexa5 As String Dim AUDATEX As String Dim nr1 As String Dim marca1 As String Dim anexa4 As String Const strDrive As String = "D:\MIHAI\DOSARE\BAAR\" raport = Trim(ActiveDocument.BuiltInDocumentProperties("Title").Value) BAAR = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Value), "/", ".") & Chr(32) nr = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("Company").Value), Chr(150), "") marca = ActiveDocument.BuiltInDocumentProperties("Comments").Value nr1 = Replace(Trim(ActiveDocument.BuiltInDocumentProperties("Company").Value), Chr(150), "-") marca1 = marca & ", " & nr1 data = ActiveDocument.BuiltInDocumentProperties("Content status").Value cinci = Right(Replace(Trim(ActiveDocument.BuiltInDocumentProperties("keywords").Value), "/", ".") & Chr(32), 6) cinci1 = Replace(cinci, " ", "") primit = "BAAR-Dosarxxx" & "_" & cinci1 & "-" & data & " Mihai" fisword = "R" & raport & "_" & BAAR & nr & " " & marca FOLDER = "BAAR-Dosarxxx" & raport & "_" & cinci1 & " " & nr & " " & marca & "-" & data & " Mihai FIN" anexa1 = "Anexa4_R" & raport & "_" & "DevizAudatex " & nr anexa5 = "Anexa5_R" & raport & "_" & "Evaluare auto " & nr Selection.Font.Bold = True anexa4 = "Anexa4" Selection.Font.Bold = False strPath = "D:\MIHAI\DOSARE\BAAR" strSubFolderNewName = strDrive & FOLDER Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(strPath) For Each oSubFolder In oFolder.SubFolders If Not oSubFolder.Name Like "MICHAEL_*" Then 'Optional strSubFolderPath = oSubFolder.Path Name strSubFolderPath As strSubFolderNewName Exit For End If 'Optional Next oSubFolder lbl_Exit: Set oFSO = Nothing Set oFolder = Nothing Set oSubFolder = Nothing FileCopy strDrive & "RP.vcp", strDrive & FOLDER & "\RP.vcp" Exit Sub End Sub What I need to do is next: If the file Mail AU.docx is in strDrive & FOLDER then create a new docx file named AU.docx in the path strDrive that contains the following text: "Raport de verif pt. dosar BAAR (where BAAR is the string I defined) In atentia d-lui Adrian Uta, Urmare a verificarii dosarului BAAR auto pagubit marca marca (where marca is the string I defined) va transmitem atasat raportul de verificare. Rog confirmati primirea. Cu stima, Mihai STAICU" If the file Mail CT.docx is in strDrive & FOLDER then create a new docx file named CT.docx in the path strDrive that contains the following text: " Raport de verif pt. dosar BAAR (where BAAR is the string I defined) In atentia d-lui Cristi Turcu, Urmare a verificarii dosarului BAAR auto pagubit marca marca (where marca is the string I defined) va transmitem atasat raportul de verificare. Rog confirmati primirea. Cu stima, Mihai STAICU " If the file Mail EN.docx is in strDrive & FOLDER then create a new docx file named EN.docx in the path strDrive that contains the following text: " Raport de verif pt. dosar BAAR (where BAAR is the string I defined) In atentia d-lui Emilia Negoita, Urmare a verificarii dosarului BAAR auto pagubit marca marca (where marca is the string I defined) va transmitem atasat raportul de verificare. Rog confirmati primirea. Cu stima, Mihai STAICU " Anyone has any ideas ? Thank you so much. Last edited by macropod; 11-10-2016 at 01:04 AM. Reason: Added code tags & formatting |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to highlight repeated words in word file and extract into excel file | aabri | Word VBA | 1 | 06-14-2015 07:20 AM |
Word 2007 , when I save a .doc or .docx file the file type is showing "Empty" | Tomc29 | Word | 9 | 06-10-2015 03:04 AM |
How to create a MS word file that automatically logs something specific inside other WORD files? | meys | Word VBA | 1 | 01-04-2015 05:22 AM |
Macro to create new word doc and save the file using String found in the document | VBNation | Word VBA | 2 | 02-08-2013 07:14 AM |
Word Macro That Checks a Check Box Form Field When File Print is Executed | DKerne | Word VBA | 4 | 06-09-2011 11:54 AM |