Hi all,
I have a data set that is getting stored in a sheet(of the same workbook) from user's input(through userform).
The data which is stored in the sheet(sheet1) is in the following format(rows are added one after another under the following headings as the user gives their input through userform):
Employee Name EmployeeID Name of Idea Idea Synopsis Process_Impact
The job is:
I am copying the data from sheet1(under a loop), pasting it into the "template" sheet (of same workbook),generating a word doc, copying the template data and paste the same into the word doc as excel table.For each row of data I am creating a separate word doc.
The problem I am facing is:
Whenever the excel data is pasted into the newly created word doc, the formating of the word content is going for a toss, and I am not able to manage this portion of the work.I have tried different ways to maintain the proper "look and fill" of the word content but not able to manage it properly.
I want the word doc to be created in the following format
Employee Name: ____________________________
ID: ______________
Name of the Idea: _______________________________________________________________________
Synopsis:
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Benefits / Process Impact:
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
______________________________________________________________________
As of now I have tried in this way to acheive the same:
Sub NewWordDoc()
Dim tempidea As String
Dim r As Integer
r = 1
'Dim t As Word.Range
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application.12")
appWD.Visible = True
Sheets("Data").Select
FinalRow = Range("A9999").End(xlUp).Row
For i = 2 To FinalRow
tempidea = "Idea" & r
Sheets("Data").Select
Range("A" & i & ":E" & i).Copy
Sheets("Template").Select
Range("D3").PasteSpecial Transpose:=True
Range("A1:F8").Copy
appWD.Documents.Add
appWD.Selection.Paste
' With appWD.Selection
' .PasteExcelTable linkedtoexcel:=False, wordformatting:=True, RTF:=False
' .TypeParagraph
' End With
' Set t = appWD.Documents.Add.Content
'' t.Paste
' With t 'working with the table range
' .Style = "GreenBar" 'set the style created for the table
' 'we can use the range object to do some more formatting
' 'here, I'm matching the table with using the Excel range's properties
' .Tables(1).Columns.SetWidth (Rng.Width / Rng.Columns.Count), wdAdjustSameWidth
' End With
appWD.ActiveDocument.SaveAs Filename:=tempidea
r = r + 1
appWD.ActiveDocument.Close
Next i
appWD.Quit
End Sub
Please help me understand what should I exactly do to create a well formatted word doc from excel data.
Regards,
Kaushik
I have a data set that is getting stored in a sheet(of the same workbook) from user's input(through userform).
The data which is stored in the sheet(sheet1) is in the following format(rows are added one after another under the following headings as the user gives their input through userform):
Employee Name EmployeeID Name of Idea Idea Synopsis Process_Impact
The job is:
I am copying the data from sheet1(under a loop), pasting it into the "template" sheet (of same workbook),generating a word doc, copying the template data and paste the same into the word doc as excel table.For each row of data I am creating a separate word doc.
The problem I am facing is:
Whenever the excel data is pasted into the newly created word doc, the formating of the word content is going for a toss, and I am not able to manage this portion of the work.I have tried different ways to maintain the proper "look and fill" of the word content but not able to manage it properly.
I want the word doc to be created in the following format
Employee Name: ____________________________
ID: ______________
Name of the Idea: _______________________________________________________________________
Synopsis:
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
Benefits / Process Impact:
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
______________________________________________________________________
As of now I have tried in this way to acheive the same:
Sub NewWordDoc()
Dim tempidea As String
Dim r As Integer
r = 1
'Dim t As Word.Range
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application.12")
appWD.Visible = True
Sheets("Data").Select
FinalRow = Range("A9999").End(xlUp).Row
For i = 2 To FinalRow
tempidea = "Idea" & r
Sheets("Data").Select
Range("A" & i & ":E" & i).Copy
Sheets("Template").Select
Range("D3").PasteSpecial Transpose:=True
Range("A1:F8").Copy
appWD.Documents.Add
appWD.Selection.Paste
' With appWD.Selection
' .PasteExcelTable linkedtoexcel:=False, wordformatting:=True, RTF:=False
' .TypeParagraph
' End With
' Set t = appWD.Documents.Add.Content
'' t.Paste
' With t 'working with the table range
' .Style = "GreenBar" 'set the style created for the table
' 'we can use the range object to do some more formatting
' 'here, I'm matching the table with using the Excel range's properties
' .Tables(1).Columns.SetWidth (Rng.Width / Rng.Columns.Count), wdAdjustSameWidth
' End With
appWD.ActiveDocument.SaveAs Filename:=tempidea
r = r + 1
appWD.ActiveDocument.Close
Next i
appWD.Quit
End Sub
Please help me understand what should I exactly do to create a well formatted word doc from excel data.
Regards,
Kaushik