![]() ContentControls(3).Range.Text = Sheets("Model").Range("X4").Value2 ContentControls(2).Range.Text = Format(Date, "mm/dd/yyyy") ContentControls(1).Range.Text = Sheets("Model").Cells(4, 2).Value2 ThisWorkbook.Sheets("Model").Range("B4").Value & _ Set oWordDoc = (FlName)įormat(ThisWorkbook.Sheets("Model").Range("B14").Value, "YYYY") & _ '~~> I created Word instance so I have to close it as well Set oWordApp = CreateObject("Word.Application") '~~> If not open then create a new word application instance Set oWordApp = GetObject(, "Word.Application") '~~> Establish an Word application object if open Private Const wdFormatXMLDocument As Integer = 12ĭim oWordApp As Object, oWordDoc As Object You do not need to add references to the MS Word program because I have used Late Binding. Thank you in advance for any help.Īre you attempting this (UNTESTED)? I've commented on on the code, but if you have any problems, just ask. ![]() I hope I've posted this request properly. I've researched this for hours and tried multiple solutions, including commenting out all of the Copy Data block to try and zero in on the error. WDoc.ContentControls(3).Range.Text = Sheets("Model").Range("X4")ĪctiveDocument.SaveAs Filename:=ActiveDocument.Path & "\" & Format(Sheets("Model").Range("B14"), "YYYY") & " " & ThisWorkbook.Sheets("Model").Range("B4") & " " & Format(Date, "YYYY-mm-dd") & ".docx" WDoc.ContentControls(2).Range.Text = Format(Date, "mm/dd/yyyy") WDoc.ContentControls(1).Range.Text = Sheets("Model").Cells(4, 2) Set wordApp = CreateObject("word.Application") Note: When you use the keyboard shortcut key Ctrl + V, the selected data is copied to Excel as with the source formatting. I make use of Microsoft 365 Apps for Business. I'm sure it's because I'm still learning how to use and create application objects within VBA code. But after another run, I encounter Run-time Error 462. On the first try, this procedure operates as predicted. ![]() When launched, it will open a Word document already in existence (stored in the same directory as the Excel workbook), copy data from Excel workbook cells into the Word document, save the Word document with a new name (also in the same directory), and then delete the original Word document. A VBA macro I created is housed in an Excel worksheet.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |