Link to home
Start Free TrialLog in
Avatar of varesources
varesourcesFlag for Afghanistan

asked on

Is it possible to use a macro to copy info from an excel doc to a word doc?

I have an excel workbook (see image) and a word document. The word document needs information in it that are in specific cells of the excel workbook. Is it possible to have a macro do this? If the document needs to be in the excel workbook that is fine.

It would need to do this several times, once for each group of data. In the image the first group of data would be T6:T7, Y8, and AG8. The second group of data would be T10:T16, Y17, and AG17.

I have a macro that converts a sheet to a pdf so after copying each group of data to the word doc or sheet it will need to run my pdf macro and then clear the copied data to prepare for the next group of data.

I hope this isn't asking too much.

Capture.JPG
Avatar of varesources
varesources
Flag of Afghanistan image

ASKER

I found the following through Bing but I'm not sure if it is a good starting place.
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

Open in new window

Anyone?
Avatar of Saqib Husain
Why don't you upload a sample file? It would be easier for me to work on a file instead of trying to build one then work on it.

Saqib
Here is an example of the data and the word document.
EEData.xlsm
EEDoc.docx
I think that these might be the steps needed.

1. Copy group of information from Sheet1 to Sheet2
2. Word document auto updates info because the cells are linked to the Word doc.
3. Save as PDF macro in Word is run.
4. Sheet2 info is cleared.
5. Start over.
Hello, I am sorry I had lost track of this question. Do you still want to continue with it?
ASKER CERTIFIED SOLUTION
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.