Open Close Save As Word FileThis program opens a word file on a predefined location and saves the file with another name to another place.
ExplanationIn order to make the program work the reference “Microsoft Word XX.X Object Library” needs to be enabled. The program opens a word file on a predefined place and saves the file with another name to another place. This can be useful when making quotations or other processes that need customization with text from different databases. The communication between word and excel is fully supported. An example file of the code is possible to download at the end of this web site, enjoy! Or just copy and paste the code directly from this page.
CodeSub Open_Close_Save_As_Word_File()
Dim Open_Close_Save_As_Word_File_APP As Word.Application Dim Open_Close_Save_As_Word_File_DOC As Word.Document Set Open_Close_Save_As_Word_File_APP = CreateObject("Word.Application")
Dim PlaceOfWordFile As String Dim NameOfWordFile As String Dim NewPlaceOfWordFile As String Dim NewNameOfWordFile As String
PlaceOfWordFile = Range("B4").Value NameOfWordFile = Range("B5").Value NewPlaceOfWordFile = Range("B6").Value NewNameOfWordFile = Range("B7").Value
NamePlace = PlaceOfWordFile + "\" + NameOfWordFile NewNamePlace = NewPlaceOfWordFile + "\" + NewNameOfWordFile
Open_Close_Save_As_Word_File_APP.Visible = True Set Open_Close_Save_As_Word_File_DOC = Open_Close_Save_As_Word_File_APP.Documents.Open(NamePlace, ReadOnly:=True)
Open_Close_Save_As_Word_File_DOC.SaveAs (NewNamePlace) Open_Close_Save_As_Word_File_APP.Quit
Set Open_Close_Save_As_Word_File_DOC = Nothing Set Open_Close_Save_As_Word_File_APP = Nothing
End Sub
Download excel file! Open_Close_Save_As_Word_File.xls |
Thx so lot for you job,I can to progress within.