Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 08-13-2018, 04:20 AM
macropod's Avatar
macropod macropod is offline Need macro to fill the values in msword based on the excel sheet info Windows 7 64bit Need macro to fill the values in msword based on the excel sheet info Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub GetExcelData()
Application.ScreenUpdating = False
'Note: A VBA Reference to the Excel Object Model is required, via Tools|References
Dim xlApp As New Excel.Application, xlWkBk As Excel.Workbook, xlWkSht As Excel.Worksheet
Dim StrWkBkNm As String, i As Long, j As Long, r As Long
StrWkBkNm = ThisDocument.Path & "\Data to fill.xlsx"
If Dir(StrWkBkNm) = "" Then
  MsgBox "Cannot find the designated workbook: " & StrWkBkNm, vbExclamation
  Exit Sub
End If
With xlApp
  .Visible = False
  .DisplayAlerts = False
  Set xlWkBk = .Workbooks.Open(FileName:=StrWkBkNm, ReadOnly:=True, AddToMRU:=False)
End With
Set xlWkSht = xlWkBk.Worksheets("Sheet1")
With ActiveDocument
  For i = 1 To .Tables.Count
    r = i + 1
    With .Tables(i)
      .Cell(2, 2).Range.Text = "PV: " & xlWkSht.Range("B" & r).Value
      With .Cell(3, 2).Range
        .ContentControls(1).Checked = (xlWkSht.Range("F" & r).Value = "Y")
        .ContentControls(2).Checked = (xlWkSht.Range("F" & r).Value = "Y")
        .ContentControls(3).Checked = (xlWkSht.Range("G" & r).Value = "Y")
      End With
      With .Cell(3, 1).Range
        With .ContentControls(1)
          .Type = wdContentControlText
          .Range.Text = xlWkSht.Range("A" & r).Value
          .Type = wdContentControlDropdownList
        End With
        With .ContentControls(2)
          .Type = wdContentControlText
          .Range.Text = xlWkSht.Range("D" & r).Value
          .Type = wdContentControlDropdownList
        End With
        With .ContentControls(3)
          .Type = wdContentControlText
          .Range.Text = xlWkSht.Range("C" & r).Value
          .Type = wdContentControlDropdownList
        End With
      End With
    End With
  Next
End With
xlWkBk.Close False
xlApp.Quit
Set xlWkSht = Nothing: Set xlWkBk = Nothing: Set xlApp = Nothing
Application.ScreenUpdating = True
End Sub
Note: You would get more meaningful content in the dropdowns if your Excel data actually matched the dropdown choices...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need macro to fill data from different sheets based on selected item from drop down skorasika Excel Programming 1 03-13-2015 11:25 AM
Newbie to excel for starters, needing to transfer info from sheet2 to universe sheet. rogcar75 Excel 0 08-12-2014 07:21 AM
Color-fill a range of cells, based on text in a different sheet. Possible? unittwentyfive Excel 2 06-01-2014 06:48 AM
Need macro to fill the values in msword based on the excel sheet info link conditional info in word based on excel list stijnvanhoof Mail Merge 1 11-13-2012 01:55 PM
Need macro to fill the values in msword based on the excel sheet info Open Word w Excel & fill Word textboxes w info from Excel fields runtime error 4248 Joe Patrick Word VBA 2 01-30-2012 07:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft