Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-20-2015, 10:10 AM
harry.ayre harry.ayre is offline When content controls are deleted, my macro does not work as I would like. Windows 7 64bit When content controls are deleted, my macro does not work as I would like. Office 2013
Novice
When content controls are deleted, my macro does not work as I would like.
 
Join Date: Feb 2015
Posts: 2
harry.ayre is on a distinguished road
Default When content controls are deleted, my macro does not work as I would like.

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!
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
When content controls are deleted, my macro does not work as I would like. VBA to set Content controls as non printing Sammie0Sue Word VBA 21 01-12-2021 04:44 PM
When content controls are deleted, my macro does not work as I would like. 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
When content controls are deleted, my macro does not work as I would like. 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

Other Forums: Access Forums

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