PDA

View Full Version : [SOLVED:] need vba code to export data from excel to word file



jackhack33
07-02-2022, 07:38 AM
Dear experts

I have fallen in data to transpose from excel to word manually i am in need of vba code help ,

i have set of data which is need to copy first 2 rows only 8 columns A:H paste into word with header point

The data layer segregate as two layer FY 19-20 one row, FY 21-22 second row
first two row copy with header paste into word as vertical
third and fourth row as another segment with header value paste into word
fifth and sixth row as another segment with header value paste into word

thanks

snb
07-02-2022, 08:02 AM
There's no VBA in the files.
What VBA did you produce yourself ?

Aussiebear
07-02-2022, 01:13 PM
I have fallen in data




Never mind Jackhack33, it'll wash off eventually. In the mean time please stand downwind of everybody

Paul_Hossler
07-02-2022, 01:58 PM
Never mind Jackhack33, it'll wash off eventually. In the meantime please stand downwind of everybody

:rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotl augh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh: :rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotl augh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh: :rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotlaugh::rotl augh:

jackhack33
07-02-2022, 05:19 PM
no I need vba code to export data from excel to word file

snb
07-03-2022, 02:23 AM
I still need an answer to my question.

jackhack33
07-03-2022, 06:23 AM
i had tried with my code but it not copy as each 2 segment into one page all range copy in one page i want each 2rows date in one page
i want set location path on code to save word on particular path file
help me on this




Sub run()
Dim wdDoc As Word.document, wdTbl As Word.Table, wdApp As Object, wdRng As Word.Range
Dim iRow As Integer, aSheet As Worksheet, iCol As Integer, iPair As Integer
Dim sPath As String
Set aSheet = ActiveSheet
iRow = 2
sPath = ActiveWorkbook.Path & "\"
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True

Set wdDoc = wdApp.Documents.Add(sPath & "OUTPUT_RESULT-FILE.docx")

Do While aSheet.Cells(iRow, 1).Value <> ""
Set wdRng = wdDoc.Range
wdRng.Collapse Direction:=0
wdRng.InsertBefore Chr(13) & Chr(13)
wdRng.Collapse Direction:=0
wdRng.FormattedText = wdDoc.Tables(1).Range.FormattedText
Set wdTbl = wdRng.Tables(1)
For iPair = 0 To 1
For iCol = 0 To 7
wdTbl.Cell(iCol + 1, iPair + 2).Range.Text = aSheet.Cells(iRow, 1).Offset(iPair, iCol).Value
Next iCol
Next iPair
iRow = iRow + 2
Loop
End Sub


pls find the error attachment

thanks

jolivanes
07-05-2022, 04:46 PM
https://www.excelforum.com/excel-programming-vba-macros/1381395-need-vba-help-to-export-data-from-excel-to-word-as-2-header.html#post5694382

Aussiebear
07-05-2022, 05:14 PM
All is not well in the kingdom.... Cross posting, why do people think they can get away with it not being noticed? The internet makes the world a small place and when you are discussing a simple topic of VBA its even smaller. Jackhack33, since you were in the mood for cross posting is there anywhere else you might have cross posted?

jackhack33
07-05-2022, 05:33 PM
sorry for that i post across forum might be get solution soon for thread by the way of attitude, i delete my account after here never ask free help on forum
thanks all experts

jackhack33
07-05-2022, 05:35 PM
No knowledge of coding

jackhack33
07-05-2022, 05:36 PM
i had tried with my code but it not copy as each 2 segment into one page all range copy in one page i want each 2rows date in one page
i want set location path on code to save word on particular path file
help me on this



No coding knowledge


pls find the error attachment

thanks

Aussiebear
07-05-2022, 06:19 PM
@jackhack33 Please read the following A message to forum cross posters (http://www.excelguru.ca/node/7) it will explain why we like people to indicate cross posts. As to your coding issue. I'm not confident with the code that you were given over at Excelforum.com because it talks about using tables within Word. A quick look at some older type code shows an example of copying an Excel range as an Object and then pasting as this Object as a Word.Selection which seems to paste to a new "page" for each Object. However it also requests a clearance of the clipboard per transfer of Object and as such is time consuming. I will continue to seek a solution from the Internet but I have yet to find anything that resembles that which you ask for. In the mean time please read the link provided

macropod
07-06-2022, 07:41 AM
No knowledge of coding
You don't even need code for this! It can all be done with a fairly basic mailmerge.

Also cross-posted at:
VBA code to export data to word with header values (msofficeforums.com) (https://www.msofficeforums.com/excel-programming/49293-vba-code-export-data-word-header-values.html)
Need vba code to export row values into msword from excel | VBA & Macros | Excel Forum • My Online Training Hub (https://www.myonlinetraininghub.com/excel-forum/vba-macros/need-vba-code-to-export-row-values-into-msword-from-excel)