GirishDhruva
Active Member
- Joined
- Mar 26, 2019
- Messages
- 308
Hi Everyone,
Here i have tried with some data that should be added from Excel to Word, later convert from Excel to Word and Good thing is that below code runs, but after executing with some sheets it throws me a run time error and code exits
Can anyone help me to solve this out
Below is my workbook which i am working
https://app.box.com/s/slwwvm6zrdt7po8ecilfs7zi0pbeuta1
Below is my code
Thanks in advance
Dhruv
Here i have tried with some data that should be added from Excel to Word, later convert from Excel to Word and Good thing is that below code runs, but after executing with some sheets it throws me a run time error and code exits
Can anyone help me to solve this out
Below is my workbook which i am working
https://app.box.com/s/slwwvm6zrdt7po8ecilfs7zi0pbeuta1
Below is my code
Code:
Sub error()
Dim appWD As Word.Application
Dim lastrow As Long
Dim name As String
Dim rng As Range
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
Application.ScreenUpdating = False
Sheets("Revision").Select
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
filesave = Range("N2").Value
For i = 2 To lastrow
Sheets("Revision").Select
emp_id = Range("A" & i).Value
name = Range("B" & i).Value
Range("B" & i).Copy Destination:=Sheets("Template").Range("A1")
Range("D" & i).Copy Destination:=Sheets("Template").Range("A2")
Range("E" & i).Copy Destination:=Sheets("Template").Range("A3")
Range("B" & i).Copy Destination:=Sheets("Template").Range("F16")
Range("D" & i).Copy Destination:=Sheets("Template").Range("F17")
Range("B" & i).Copy Destination:=Sheets("Template").Range("B4")
Range("M" & i).Copy Destination:=Sheets("Template").Range("D4")
Range("F" & i & ":L" & i).Copy
Worksheets("Template").Select
Range("C8").PasteSpecial Transpose:=True
Range("B11:D11").Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
Range("A1:C4").Copy
appWD.Documents.Add
With appWD
.Selection.Font.Bold = True
.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Selection.TypeText Text:="PROMOTION & SALARY REVISION LETTER"
.Selection.TypeParagraph
.Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
.Selection.InsertDateTime
.Selection.TypeParagraph
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Selection.PasteSpecial DataType:=wdPasteText
.Selection.Font.Bold = False
.Selection.TypeParagraph
.Selection.TypeText Text:="This is to keep you informed that your designation & salary has been revised with effect from "
.Selection.TypeParagraph
'.Selection.Font.Bold = True
'.Selection.TypeText Text:="30th May 2019"
'.Selection.Font.Bold = False
End With
Worksheets("Template").Select
Range("D4").Copy
With appWD
.Selection.Font.Bold = True
.Selection.Paste
.Selection.Font.Bold = False
End With
Worksheets("Template").Select
Range("D8").Formula = "=RC[-1]*12"
Range("D9").Formula = "=RC[-1]*12"
Range("D10").Formula = "=RC[-1]*12"
Range("D11").Formula = "=RC[-1]*12"
Range("D12").Formula = "=RC[-1]*12"
Range("D13").Formula = "=RC[-1]*12"
Range("D14").Formula = "=RC[-1]*12"
Range("B14:D14").Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
Set rng = Range("C7:C14")
With rng.Borders
.LineStyle = xlContinuous
.Color = vbBlack
.Weight = xlThin
End With
Range("B6:D14").Copy
With appWD
.Selection.PasteExcelTable LinkedToExcel:=False, _
WordFormatting:=False, RTF:=False
.Selection.TypeParagraph
.Selection.TypeText Text:="The remuneration stated above is subject to the terms and conditions of your contract of employment of which this is a part"
.Selection.TypeParagraph
.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Selection.Font.Bold = True
.Selection.TypeText Text:="ACKNOWLEDGED AND AGREED"
.Selection.TypeParagraph
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Selection.TypeText Text:="Yours faithfully"
.Selection.TypeParagraph
.Selection.TypeText Text:="XYZ Private Limited.,"
.Selection.TypeParagraph
.Selection.TypeParagraph
.Selection.TypeText Text:="ABC"
.Selection.TypeParagraph
.Selection.TypeText Text:="CEO ACCEPTANCE"
'.Selection.TypeParagraph
'.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
'.Selection.TypeText Text:="ACCEPTANCE"
End With
Worksheets("Template").Select
Range("E16:F17").Copy
With appWD
.Selection.TypeParagraph
.Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
.Selection.PasteSpecial DataType:=wdPasteText
.ActiveDocument.SaveAs Filename:=filesave & "\" & emp_id & "_" & name
.ActiveDocument.Close
End With
Application.CutCopyMode = False
Sheets("Revision").Select
'Application.Wait (Now + TimeValue("0:00:02"))
Next i
'Application.ScreenUpdating = True
appWD.Quit
End Sub
Thanks in advance
Dhruv