Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 08-27-2018, 12:16 AM
shaztastic shaztastic is offline Push Word content control data and excel cells Windows 7 64bit Push Word content control data and excel cells Office 2010 32bit
Novice
Push Word content control data and excel cells
 
Join Date: Aug 2018
Location: Wales, UK
Posts: 10
shaztastic is on a distinguished road
Default

So the excel file(s) are opened from the code in word (see below) depending on which checkboxes are checked.
Is it possible maybe to check that the required content controls have at least some data (it would be up to the user to make sure its correct)? I am only interested in 5 out of maybe 30 of the content controls in the word document.
I only want the data to be pushed to excel if the workbooks are opened from the code within the word document.
Sorry for not explaining it better and thanks for taking the time to look at this


Code:
 
Sub Open_CheckedCCs_Click()
Dim aCC As ContentControl, xlApp As Object, xlWkBk As Object
  Dim sPath As String, sFullPath As String
    sPath = "C:\Temp\MyDocs\"    'xl files in fixed location
  On Error Resume Next
    Set xlApp = GetObject(, "Excel.Application")
  On Error GoTo 0
  For Each aCC In ActiveDocument.Range.ContentControls
    If aCC.Type = wdContentControlCheckBox Then
      sFullPath = sPath & aCC.Tag
      If aCC.Checked And fFileExists(sFullPath) Then
        If xlApp Is Nothing Then Set xlApp = CreateObject("Excel.Application")
        Set xlWkBk = xlApp.Workbooks.Open(sFullPath)
        xlApp.Visible = True
        xlWkBk.Activate
      End If
    End If
  Next aCC
  
End Sub

Function fFileExists(sPath As String) As Boolean
  Dim fso As Object
  Set fso = CreateObject("Scripting.FileSystemObject")
  fFileExists = fso.FileExists(sPath)
End Function
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Push Word content control data and excel cells Importing content control data from excel and populate two fields on selected dropdown badarlodhi Word VBA 8 02-08-2023 10:47 AM
Push Word content control data and excel cells Export Word Drop-Down Content Control to Excel Specific Sheet nolanthomas32 Word VBA 4 09-19-2017 06:25 AM
Push Word content control data and excel cells Edit table cells based on content control selection gennatr12 Word VBA 7 03-26-2017 08:51 PM
Push Word content control data and excel cells Content Control Copy - Copies Data and CC itself shammi_raj Word 3 03-30-2016 07:01 PM
Push Word content control data and excel cells Push data automatically from Acess or Excel to create a Gantt chart in Project GST2212 Project 3 07-06-2012 12:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:01 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