Results 1 to 5 of 5

Thread: Excel 365 VBA to place values in Word 365 Content Controls Rich Text
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Mar 2010
    Location
    New England
    Posts
    416
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Excel 365 VBA to place values in Word 365 Content Controls Rich Text

    Hello all,

    Now they want to add information to a form from the Excel workbook NoSparks helped me code.

    The code is in Excel and is below. I have it calling to where I have the Word template fine.
    It goes to a word document with more content controls then what I am requesting to be filled.
    So
    1) How do I engage a checkbox
    2) Go to specific content controls not just the first one found.
    Code:
    Sub Fuzzy()
    
    
        Dim wordApp As Word.Application
        Dim wDoc As Word.Document
        Dim r As Integer
        
        Doc_land = "location on server"
        
        Set wordApp = CreateObject("word.application")
        Set wDoc = wordApp.Documents.Open(Doc_land & "/" & Range("K31").Value & ".docx")
        wordApp.Visible = True
        r = 2
        
        For i = 1 To 1
         With wDoc
            .ContentControls(i).Range.Text = Sheets("Released Product").Cells(r, 3) 'Text description
            .ContentControls(i).Range.Text = Sheets("Released Product").Cells(r, 6) 'Numerical Value
            .ContentControls(i).Range.Text = Sheets("Released Product").Cells(r, 7) 'Date opened
            .ContentControls(i).Range.Text = Sheets("Released Product").Cells(r, 5) 'Date closed
            r = r + 1
         End With
        Next i
        
       
    End Sub
    I have labeled the Content Controls with unique names and tags if that helps.
    This opens and places initial value(Text description) in first content control box as an erroneous date but nothing else.
    I almost have this whipped.
    Any ideas?

    DThib

  2. #2
    Board Regular
    Join Date
    Mar 2010
    Location
    New England
    Posts
    416
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel 365 VBA to place values in Word 365 Content Controls Rich Text

    Just figured out one of the problems, changing i value to the number of Control box I want to start at (For i = 11 to 14).
    They are all, however, still giving me dates for all values, although 2 of these are text.

    DThib

  3. #3
    Board Regular
    Join Date
    Mar 2010
    Location
    New England
    Posts
    416
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel 365 VBA to place values in Word 365 Content Controls Rich Text

    bump

    Need to trigger a checkbox to true in same document and increment name Excel saveas ..
    Last edited by DThib; Sep 19th, 2019 at 12:33 PM.

  4. #4
    Board Regular
    Join Date
    Mar 2010
    Location
    New England
    Posts
    416
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel 365 VBA to place values in Word 365 Content Controls Rich Text

    Can anyone help?
    Checkbox on word doc is not working
    I need to have the code run through the table rows and produce individual documents for each match.

    Here is the latest iteration of my code:
    Code:
    Sub Mud()
    
    
        Dim wordApp As Word.Application
        Dim wDoc As Word.Document
        Dim RPs As Worksheet, i As Integer, r As Long
        Dim COr As Range, RPr As Range
        Dim cel As Range, fndRng As Range, r2 As Long
        
        Doc_Land = "\\server\"
        
        Set wordApp = CreateObject("Word.Application")
        Set wDoc = wordApp.Documents.Open(Doc_Land & "/" & Range("K31").Value & ".docx")
    
    
        wordApp.Visible = True
        Set RPs = ThisWorkbook.Sheets("Released Product")
        With RPs
            Set RPr = .Range("A1", .Range("A" & .Rows.Count).End(xlUp))
        End With
        r2 = RPs.Cells(Rows.Count, "B").End(xlUp).Row
        r = 1 + r2
        For Each cel In RPr
          Set fndRng = RPr.Find(What:=cel.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
          SearchDirection:=xlNext, MatchCase:=False)
           If Not fndRng Is Nothing Then
             For r = r2 To 1
                If cel.Offset(r, 0) = RPs.Range("K1") Then
                  With wDoc
                    .Checkbox(10) = True ' CheckBox
                    .ContentControls(11).Range.Text = cel.Offset(r, 2).Value
                    .ContentControls(12).Range.Text = cel.Offset(r, 5).Value
                    .ContentControls(13).Range.Text = cel.Offset(r, 6).Value
                    .ContentControls(14).Range.Text = cel.Offset(r, 4).Value
                    .SaveAs Doc_Land & "/" & RPs.Range("K29")
                    .Close
                 End With
                End If
            Next r
          End If
        Next cel
         MsgBox "All Forms complete!", vbCritical + vbExclamation + vbOKOnly, "Release 1001"
    
    
       
    End Sub
    DThib
    Last edited by DThib; Sep 19th, 2019 at 01:16 PM.

  5. #5
    Board Regular
    Join Date
    Mar 2010
    Location
    New England
    Posts
    416
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel 365 VBA to place values in Word 365 Content Controls Rich Text

    Hello,

    I figured it Out!

    Works well now, thanks to all who at least looked at this

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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