Texasthierry
02-15-2016, 08:10 AM
Hi all, excel is not my birth language and I didn't success to finish this VBA :banghead:.
From an excel (2010) database it does open 3 word sheets (2010), linked the data from excel, save the word in a different folder with specific name and unlinked them. It works fine except for the headers (I don't have footers), it doesn't unlink them. Any idea on how to make it happen ? Thanks for your help.
Sub Generate()
Dim objWord
Dim objDoc1
Dim objDoc2
Dim objDoc3
Dim WO As String
Dim family As String
Dim var As String
'Get infos for file name
Sheets("DATA").Select
WO = Sheets("DATA").Cells(7, 2).Value
SN = Sheets("DATA").Cells(11, 2).Value
family = Sheets("DATA").Cells(1, 11).Value
var = Sheets("DATA").Cells(6, 2).Value
Directory = "C:\Forms Saved\"
Nom1 = "ICS " & family & var & " " & SN & " " & WO & ".docx"
Nom2 = "WS " & family & var & " " & SN & " " & WO & ".docx"
Nom3 = "TR " & family & var & " " & SN & " " & WO & ".docx"
'Open Word files
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc1 = objWord.Documents.Open("C:\Linked ICS, WS, TR\ICS.docx")
Set objDoc2 = objWord.Documents.Open("C:\Linked ICS, WS, TR\Workscope.docx")
Set objDoc3 = objWord.Documents.Open("C:\Linked ICS, WS, TR\Tech Report.docx")
'Unlink word files
objDoc1.Fields.Unlink
objDoc2.Fields.Unlink
objDoc3.Fields.Unlink
'Saved word files
objDoc1.SaveAs (Directory & Nom1)
objDoc2.SaveAs (Directory & Nom2)
objDoc3.SaveAs (Directory & Nom3)
'Close word files
objDoc1.Close
objDoc2.Close
objDoc3.Close
objWord.Quit
End Sub
From an excel (2010) database it does open 3 word sheets (2010), linked the data from excel, save the word in a different folder with specific name and unlinked them. It works fine except for the headers (I don't have footers), it doesn't unlink them. Any idea on how to make it happen ? Thanks for your help.
Sub Generate()
Dim objWord
Dim objDoc1
Dim objDoc2
Dim objDoc3
Dim WO As String
Dim family As String
Dim var As String
'Get infos for file name
Sheets("DATA").Select
WO = Sheets("DATA").Cells(7, 2).Value
SN = Sheets("DATA").Cells(11, 2).Value
family = Sheets("DATA").Cells(1, 11).Value
var = Sheets("DATA").Cells(6, 2).Value
Directory = "C:\Forms Saved\"
Nom1 = "ICS " & family & var & " " & SN & " " & WO & ".docx"
Nom2 = "WS " & family & var & " " & SN & " " & WO & ".docx"
Nom3 = "TR " & family & var & " " & SN & " " & WO & ".docx"
'Open Word files
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc1 = objWord.Documents.Open("C:\Linked ICS, WS, TR\ICS.docx")
Set objDoc2 = objWord.Documents.Open("C:\Linked ICS, WS, TR\Workscope.docx")
Set objDoc3 = objWord.Documents.Open("C:\Linked ICS, WS, TR\Tech Report.docx")
'Unlink word files
objDoc1.Fields.Unlink
objDoc2.Fields.Unlink
objDoc3.Fields.Unlink
'Saved word files
objDoc1.SaveAs (Directory & Nom1)
objDoc2.SaveAs (Directory & Nom2)
objDoc3.SaveAs (Directory & Nom3)
'Close word files
objDoc1.Close
objDoc2.Close
objDoc3.Close
objWord.Quit
End Sub