Consulting

Results 1 to 6 of 6

Thread: Many urgent excel at vertical instead of horizontal word

  1. #1
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location

    Many urgent excel at vertical instead of horizontal word

    Hello to all the great minds of VBA.
    Is there someone who can make a macro to copy excel written down in box A: A word document again vertically A1, A2, A3, etc.
    Or because this macro works very well, but if you can touch anywhere hirizontalno instead, carry information vertically - >>> this would be the best option.
    Thanks in advance
    [vba]Sub AutoFillWordTables()

    Dim C As Long
    Dim FileFilter As String
    Dim LastCol As Long
    Dim R As Long
    Dim Rng As Excel.Range
    Dim WordFile As String
    Dim wdApp As Object
    Dim wdDoc As Object
    Dim wdTbl As Object
    Dim Wks As Worksheet

    Set Wks = Worksheets("Sheet1")
    Set Rng = Wks.Range("A1:A6")

    LastCol = Wks.Cells(Rng.Row, Columns.Count).End(xlToLeft).Column
    Set Rng = Rng.Resize(ColumnSize:=LastCol)

    FileFilter = "Word Documents(*.doc),*.doc, All Files(*.*),*.*"
    WordFile = Excel.Application.GetOpenFilename(FileFilter)

    If WordFile = "False" Then Exit Sub

    Set wdApp = CreateObject("Word.Application")
    Set wdDoc = wdApp.Documents.Open(WordFile)

    For C = 1 To LastCol
    Set wdTbl = wdDoc.Tables(C)
    For R = 1 To Rng.Rows.Count
    wdTbl.Range.Cells(R).Range.Text = Rng.Cells(R, C)
    Next R
    Next C

    wdApp.Visible = True

    Set wdApp = Nothing
    Set wdDoc = Nothing
    Set wdTbl = Nothing

    End Sub



    [/vba]

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Sorry but your post makes very little sense!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Honest I do not know how much more info you need. There is an excel file that has this code, which works perfectly but carries information in "word" horizontally, and because you do not know much - obviously need somewhere to change a little something in the code itself, instead of horizontally to vertically transmitted in writing "word" document.
    Open a new "word" - insert table, only 6 rows down and 6 to the right and look at the attached picture. Thanks in advance
    Attached Images Attached Images

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Try changing this bit[VBA]For C = 1 To LastCol
    Set wdTbl = wdDoc.Tables(C)
    For R = 1 To Rng.Rows.Count
    wdTbl.Range.Cells(R).Range.Text = Rng.Cells(R, C)
    Next R
    Next C
    [/VBA]for this[VBA]
    Set wdTbl = wdDoc.Tables(1)
    For R = 1 To Rng.Rows.Count
    wdTbl.Range.Cells(R).Range.Text = Rng.Cells(R, 1)
    Next R
    [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    [VBA]Sub snb()
    With ThisDocument.Tables(1)
    For j = 1 To .Rows(1).Cells.Count
    .Cell(j, 1).Range.Text = .Cell(1, j).Range.Text
    Next
    End With
    End Sub[/VBA]

  6. #6
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Hi Simon, thank you very much for the help from your side.
    It works perfectly. I knew it needs to be touched anywhere, but you do not understand so many macros, and wrote to ask.
    Thank you very much.
    As SNB - and put your code, but gave me an error, something is done, but no matter the important thing is that it works with other code.
    Thank you all

Posting Permissions

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