Sub saveToWord Dim I As Integer Dim finalRow as Integer Dim appWD As Object Dim myString as String Dim numberOne as String Dim numberTwo as Strng Dim myFilename As String ' Create a new instance of Word & make it visible Set appWD = CreateObject("Word.Application") appWD.Visible = True 'Find the last row with data in the database finalRow = ActiveSheet.Range("A9999").End(xlUp).Row For I = 2 To finalRow myString = ActiveSheet.Range("a" & i).Value ' these two cells are both alphanumeric cells; first two characters are always numbers numberOne = Left(ActiveSheet.Range("b" & i).Value, 2) numberTwo = Left(ActiveSheet.Range("c" & i).Value, 2) ' Build the unique filename. ' In my Excel file these three elements are sufficient to make the filename unique myFilename = myString & " " & numberOne & " " & numberTwo ' We want to put the data from cell H into a word doc ActiveSheet.Range("H" & i).Copy ' Tell Word to create a new document appWD.Documents.Add ' Tell Word to paste the contents of the clipboard into the new document appWD.Selection.Paste ' Save the new document with the filename and close the word document appWD.ActiveDocument.SaveAs filename:= myFilename appWD.ActiveDocument.Close Next i ' Close the Word application appWD.Quit End Sub
Member requests are more likely to be responded to.
Members can monitor the statuses of their requests from their account pages.
A CCM membership gives you access to additional options.