hi,
i'm using the following code to modify a standard word document and save it to disk with a new file name.
however, i cannot change header text or text inside of a table with this code. how should i modify it to find and replace text inside these elements too?
best regards,
bm
i'm using the following code to modify a standard word document and save it to disk with a new file name.
Code:
Sub CreateQuote() '*************************************************************************** 'Quotation part '*************************************************************************** Dim appWord As New Word.Application Dim intRMA, i As Integer Dim strDate, strFileName As String Dim Range As Range 'Define the path where to save the RMA.doc intRMA = InputBox("RMA Number:", "Create Quotation Document", "") strDate = Format(Now(), "yyyy-mm-dd") strFileName = "CAR " & intRMA & " Spare Part Quote.doc" 'Open the RMA Word Template appWord.Documents.Open ("C:\Documents and Settings\qtomlyc\My Documents\Attachments\NEW Spare Part Quote.doc") ' Make Word invisible through the Application object. appWord.Visible = False 'Change date in document For i = 1 To 15 Set Range = appWord.ActiveDocument.Content Range.Find.Execute FindText:="2007-XX-XX", ReplaceWith:=strDate Next i 'Change reference of RMA in document For i = 1 To 15 Set Range = appWord.ActiveDocument.Content Range.Find.Execute FindText:="XXXX", ReplaceWith:=intRMA Next i ' Save the new RMA document appWord.ActiveDocument.SaveAs "C:\Documents and Settings\qtomlyc\My Documents\Attachments\CAR " & intRMA & " Spare Part Quote.doc" ' Reminder to change header date and RMA number MsgBox "Header text not changed", vbOKOnly, "Create Quotation Document" ' Show the document to user in order to enter FAB numbers etc appWord.Visible = True ' Dispose objects to free memory Set appWord = Nothing Set Range = Nothing End Sub
best regards,
bm
Comment