I have a code that creates certificates in Word using data from excel. All certificates are created in one go. How do I change it so that it only creates a certificate for a selected row? Thanks in advance
Here is the code
'Start word and a new document
Set wd = New Word.Application
'Set worksheet where table is available
Set sh = ThisWorkbook.Sheets("Shipment")
iRow = 4
Do While sh.Range("A" & iRow).Value <> ""
'opening the word template
Set wdDoc = wd.Documents.Open(ThisWorkbook.Path & "\New Freight Certificate (Macro).docx")
wd.Visible = False
wd.Selection.Goto what:=wdgotobookmark, Name:="HBL"
wd.Selection.typetext Text:=sh.Range("A" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="MBL"
wd.Selection.typetext Text:=sh.Range("G" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="Shipper"
wd.Selection.typetext Text:=sh.Range("K" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="POL"
wd.Selection.typetext Text:=sh.Range("L" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="POD"
wd.Selection.typetext Text:=sh.Range("M" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="Type"
wd.Selection.typetext Text:=sh.Range("AB" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="ExRT"
wd.Selection.typetext Text:=sh.Range("AC" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="Volume"
wd.Selection.typetext Text:=sh.Range("O" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="Terms"
wd.Selection.typetext Text:=sh.Range("AD" & iRow).Value
wdDoc.SaveAs2 (ThisWorkbook.Path & "\" & sh.Range("A" & iRow).Value)
wdDoc.Close
Set wdDoc = Nothing
iRow = iRow + 1
Loop
End Sub
Here is the code
'Start word and a new document
Set wd = New Word.Application
'Set worksheet where table is available
Set sh = ThisWorkbook.Sheets("Shipment")
iRow = 4
Do While sh.Range("A" & iRow).Value <> ""
'opening the word template
Set wdDoc = wd.Documents.Open(ThisWorkbook.Path & "\New Freight Certificate (Macro).docx")
wd.Visible = False
wd.Selection.Goto what:=wdgotobookmark, Name:="HBL"
wd.Selection.typetext Text:=sh.Range("A" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="MBL"
wd.Selection.typetext Text:=sh.Range("G" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="Shipper"
wd.Selection.typetext Text:=sh.Range("K" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="POL"
wd.Selection.typetext Text:=sh.Range("L" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="POD"
wd.Selection.typetext Text:=sh.Range("M" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="Type"
wd.Selection.typetext Text:=sh.Range("AB" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="ExRT"
wd.Selection.typetext Text:=sh.Range("AC" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="Volume"
wd.Selection.typetext Text:=sh.Range("O" & iRow).Value
wd.Selection.Goto what:=wdgotobookmark, Name:="Terms"
wd.Selection.typetext Text:=sh.Range("AD" & iRow).Value
wdDoc.SaveAs2 (ThisWorkbook.Path & "\" & sh.Range("A" & iRow).Value)
wdDoc.Close
Set wdDoc = Nothing
iRow = iRow + 1
Loop
End Sub