![]() |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi I have been using the forums on this site for some time and have found them incredibly useful. Thank you! I have a large number of word forms with content controls in paragraphs of text as well as tables. I also have an excel sheet which pulls the values in the word form fields, in order from left to right, in to the excel sheet. Here is a copy of the code I am using. I got it from http://www.vbaexpress.com/forum/show...l=1#post257696 Sub GetFormData() Application.ScreenUpdating = False Dim wdApp As New Word.Application Dim wdDoc As Word.Document Dim CCtrl As Word.ContentControl Dim strFolder As String, strFile As String Dim WkSht As Worksheet, i As Long, j As Long strFolder = GetFolder If strFolder = "" Then Exit Sub Set WkSht = ActiveSheet i = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row strFile = Dir(strFolder & "\*.doc", vbNormal) While strFile <> "" i = i + 1 Set wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) With wdDoc j = 0 For Each CCtrl In .ContentControls j = j + 1 WkSht.Cells(i, j) = CCtrl.Range.Text Next End With wdDoc.Close SaveChanges:=False strFile = Dir() Wend wdApp.Quit Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder( 0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function Public Sub ClearSheet() 'Clear Sheet Data' Rows("6:2000").Select Selection.ClearContents End Sub The problem that I'm having is that users of the forms cannot delete any of the form fields in the word forms. If this occurs, the excel does not account for the deleted form field. Is there any way that I can code something which will leave a blank cell in excel where the form field was deleted? Any help would be very appreciated. Thanks! |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
VBA to set Content controls as non printing
|
Sammie0Sue | Word VBA | 21 | 01-12-2021 04:44 PM |
Cant type into content controls in a form after protecting document using macro
|
rgburridge | Word VBA | 4 | 01-27-2015 02:37 PM |
| Word 2010 Macro Enabled Template with Content Controls | keen1598 | Word VBA | 7 | 01-29-2014 03:17 PM |
Content Controls
|
Sammie0Sue | Word | 6 | 11-06-2013 10:56 PM |
| Macro to link 2 content controls | bortonj88 | Word VBA | 2 | 08-21-2012 06:24 AM |