The below code will help you to copy the MS Excel data into MS Word. The main thing to note here is, the Excel data is copied into Word in a table format. This is a very basic VBA code, you can extend this to add other features.
To add this code to your excel, Open VBA editor in Excel or you can press F11. Insert a module, paste this code. Come back to excel by pressing F11 again. Under macros you can see the name of subroutine 'CopyFromExcelToWord' appearing, this is your macro.
Sub CopyFromExcelToWord()
Dim objWord
Dim objDoc
Dim objRange
Dim total_rows
Dim total_cols
Dim objTable
Dim tmp_row
Dim tmp_col
total_rows = Cells(1, 10).Value
total_cols = Cells(2, 10).Value
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
Set objRange = objDoc.Range
objWord.Visible = True
objDoc.Tables.Add objRange, total_rows, total_cols
'objWord.SaveAs ("C:\Users\sanjeeva\Documents\krishna\personal\videos\a.docm")
Set objTable = objDoc.Tables(1)
objTable.Borders.Enable = True
For tmp_row = 1 To total_rows
For tmp_col = 1 To total_cols
objTable.Cell(tmp_row, tmp_col).Range.Text = Cells(tmp_row, tmp_col)
Next
Next
End Sub
Some useful tips on daily computer and mobile usage and programming. I post information and help topics on new technologies, Mobile, Computers, Office Automation.
Subscribe to:
Post Comments (Atom)
How to Fix ImportError: No module named 'flask' with virtualenv
Flask is one of the most used frameworks in Python. If you are new to the flask and if you are getting this error - ImportError: No module n...

-
A normal phone Bluetooth headset can be easily connected to a laptop and it can be used as earphones or headphones while using skype, gtalk,...
-
If you are using Windows 10 operating system and want to use virtualization on it, then you have 2 options. 1. Using Virtual Box 2. Using...
-
There are plenty of online resources to convert Numeric currencies to Text- from $200 to Dollar Two Hundred. But this is applicable only ##...

No comments:
Post a Comment