Public Function funOpenDoc() Dim tmpArray As Variant Dim LinksList As Variant Dim appWD As Word.Application Dim LastRow As Long, i As Long Dim strAddy As String, strFilename As String, strTargFile As String Dim strCode As String, strDocNo As String, strDocVer As String ' Find the last row with data in the spreadsheet With Sheets("Sheet1") LastRow = .Range("E" & .Rows.Count).End(xlUp).Row End With ' Create a new instance of Word and make it visible Set appWD = CreateObject("Word.Application") appWD.Visible = True For i = 1 To LastRow strCode = Range("B" & i).Value 'Departmental code, 3 char strDocNo = Range("C" & i).Value 'Departmental document ID, 3 char with leading zeros strDocVer = Range("D" & i).Value 'Document version number, 3 char with leading zeros strFilename = strCode & strDocNo & strDocVer strAddy = Range("F" & i).Value 'the document hyperlink address strTargFile = "C:\DocFolder\" & strFilename & ".doc" ' Tell Word to create a new document, then put in print view so headers & footers can show appWD.Documents.Open (strAddy) appWD.ActiveDocument.ActiveWindow.View.Type = wdPrintView ' Save the new document with a sequential file name. appWD.ActiveDocument.SaveAs Filename:=strTargFile ' Close the new Word document. appWD.ActiveDocument.Close Next i ' Close the Word application. appWD.Quit End Function
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.