Consulting

Results 1 to 14 of 14

Thread: need vba code to export data from excel to word file

  1. #1

    need vba code to export data from excel to word file

    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
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    There's no VBA in the files.
    What VBA did you produce yourself ?

  3. #3
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    4,997
    Location
    Quote Originally Posted by jackhack33 View Post
    I have fallen in data
    Never mind Jackhack33, it'll wash off eventually. In the mean time please stand downwind of everybody
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by Aussiebear View Post
    Never mind Jackhack33, it'll wash off eventually. In the meantime please stand downwind of everybody
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    no I need vba code to export data from excel to word file

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    I still need an answer to my question.

  7. #7
    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
    Attached Images Attached Images
    Last edited by jackhack33; 07-03-2022 at 06:27 AM. Reason: explaination

  8. #8

  9. #9
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    4,997
    Location
    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?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  10. #10
    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

  11. #11
    No knowledge of coding

  12. #12
    Quote Originally Posted by jackhack33 View Post
    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

  13. #13
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    4,997
    Location
    @jackhack33 Please read the following A message to forum cross posters 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
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  14. #14
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by jackhack33 View Post
    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)
    Need vba code to export row values into msword from excel | VBA & Macros | Excel Forum • My Online Training Hub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •