1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Populate Word Doc from Excel (Multiple Rows, Select Columns)

Discussion in 'Business Applications' started by bbartholomew, Oct 30, 2013.

Thread Status:
Not open for further replies.
  1. bbartholomew

    bbartholomew Thread Starter

    Joined:
    Oct 30, 2013
    Messages:
    1
    I am un able to get an existing word file to open. I can get the following to open a new word file. I need this to opoen an existing file.

    Sub export2Word(row)
    Dim oWD As Object
    Dim wdDoc As Object
    Dim TWB As Workbook, wsh, wsh1 As Worksheet
    Set TWB = ThisWorkbook
    On Error Resume Next
    Set oWD = GetObject(, "Word.Application")
    If Err.Number <> 0 Then Set oWD = CreateObject("Word.Application")
    Err.Clear
    Set wdDoc = oWD.documents.Add
    With wdDoc
    With .Range.paragraphs(1).Range
    .Text = "PICK UP & DELIVERY" & Chr(10)
    .Font.Size = 15
    .Font.Name = "Times New Roman"
    .Font.Bold = True
    .Font.Underline = True
    .ParagraphFormat.Alignment = 1
    End With
    With .Range.paragraphs(2).Range
    .Text = "PICK UP" & vbTab & Cells(row, "K").Value & vbTab & Chr(10)
    .Font.Size = 10
    .Font.Name = "Times New Roman"
    .Font.Bold = True
    .Font.Underline = True
    .ParagraphFormat.Alignment = 0
    End With
    With .Range.paragraphs(3).Range
    .Text = Chr(10) & Chr(10) & Chr(10) & Chr(10)
    .Font.Size = 13
    .Font.Underline = False
    .ParagraphFormat.TabStops.ClearAll
    .DefaultTabStop = Application.CentimetersToPoints(1)
    .ParagraphFormat.TabStops.Add Position:=Application.CentimetersToPoints(5), _
    Alignment:=0, Leader:=0
    End With
    With .Range.paragraphs(5).Range
    .Text = "NAME" & vbTab & Cells(row, "B").Value & vbTab & _
    Cells(row, "C").Value & Chr(10) & _
    "ADDRESS" & vbTab & Cells(row, "D").Value & vbTab & _
    Cells(row, "E").Value & Chr(10) & _
    "PHONE" & vbTab & Cells(row, "R").Value & Chr(10) & _
    "MODEL" & vbTab & Cells(row, "F").Value & Chr(10) & _
    "VIN" & vbTab & Cells(row, "G").Value & Chr(10) & Chr(10) & _
    "WORK TO PERFORM" & ": " & vbTab & Cells(row, "I").Value & Chr(10) & Chr(10) & Chr(10) & _
    "SPECIAL INSTRUCTIONS" & ": " & vbTab & Cells(row, "J").Value & Chr(10)
    .Font.Size = 13
    .Font.Name = "Times New Roman"
    .Font.Bold = False
    .ParagraphFormat.Alignment = 0
    End With
    End With
    oWD.Visible = True
    wdDoc.Activate
    End Sub
     
  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,553
    First Name:
    Hans
    Hi,
    Welcome to the forum
    You should paste your code in a code clock

    [ code ]

    no spaces in between the []

    [ / code ]

    Code:
    Set wdDoc = oWD.documents.Add
    
    To open a word doc

    Code:
    Set wdDoc = oWD.documents.Open(fullpath and name of the file)
    
    This should do the trick
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1111808

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice