To include MS word object library, go to Tools and then select References. Select the required object library as shown in the picture below.
To copy the VBA code follow the below steps
Open excel and make your table ready. This steps is as per your requirement.
Press Ctrl + F11, this will open a Visual Basic editor.
Click on insert and then module.
Module1 will appear if do not have any module. Paste the below code into this module
Go back to excel and your macro will appear under macros list. Select and click on Run to execute the macro.
Watch this video for more details explanation
Sub CreateWord()
Dim w
Dim d
Dim filename As String
'filename = "D:\\krishna\\youtube vidoes upload\\Marks Card " & Format(Date, "ddmmyy") & "_" & Second(Now())
filename = "D:\\krishna\\youtube vidoes upload\\Marks Card " & Sheets("marks_sheet").Range("G7:G7") & "_" & Sheets("marks_sheet").Range("G8:G8")
Sheets("marks_sheet").Range("a4:k25").Copy
Set d = CreateObject("Word.Application")
'If w Is Nothing Then
Set w = d.Documents.Add
d.Selection.Paste
d.Visible = True
'd.Selection.Paste ("new content")
Application.CutCopyMode = False
'ActiveDocument.Sections.Paste ("adsf")
d.ActiveDocument.SaveAs filename
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.CutCopyMode = False
Set w = Nothing
Set d = Nothing
End Sub
Thanks a lot!
ReplyDeleteOh, thanks for explanation! Work with Excel is a challenge for me. Especially when I’m in lack of time. Once I got in trouble when I had to complete my Excel project in one night. Luckily, I’ve found https://www.assignmentexpert.com/programming/excel. It seemed to be a failure, but experts helped me to get A next morning. Strongly recommend!
ReplyDeleteThis is a great explanation. I have had issues with excel assignments of late for my bachelors class. But https://excelassignmenthelp.com/ came to my rescue. Their writers are awesome.
ReplyDelete