So this works in Excel, but not in Access but I've no idea why. What is even stranger is that I have a version of this code running via Excel and this runs without any problems at all and I've lifted this section of code from that subroutine exactly as is. The code executes fine, with one exception which is the Find and Replace element in Word i.e. WordApp.Quit savechanges:=wdDoNotSaveChanges ActiveDocument.SaveAs2 FileName:=SaveAsName, FileFormat:=17 ' Cycle through all records in MailingList Query Set rs = db.OpenRecordset("qryMailingList", dbOpenDynaset, dbSeeChanges) ' Point to the relevant table in the Current Database Set WordApp = CreateObject("Word.Application") Word then replaces the found items with the. Press Ctrl+H to display the Find and Replace dialog box, type the search text into the 'Find what' box, and type c in the 'Replace with' box. To do so, enter the text you want in your document, select it, and press Ctrl+C to copy it. ' Document already exists so reference this But what you can do is replace with the contents of the Clipboard. ' Start Word and create an object (late binding) ' Creates Garda Vetting Forms NVB1 in Word and saves as PDFĭim FilePath As String, SaveAsName As String The updated code works mostly but strangely, the part of the code which finds and replaces the text string doesn't work when I run it in access. I have successfully written some VBA code in Excel which opens an existing Word document, finds and replaces a string based on information in the Excel worksheet.Īs the source data exists comes from an Access Database, I thought I would try and move the VBA code into Access and run it from there.
0 Comments
Leave a Reply. |