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

DThib

Active Member
Joined
Mar 19, 2010
Messages
464
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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
 
Upvote 0
bump

Need to trigger a checkbox to true in same document and increment name Excel saveas ..
 
Last edited:
Upvote 0
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:
Upvote 0
Hello,

I figured it Out!

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

Forum statistics

Threads
1,213,561
Messages
6,114,315
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top