Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
We are experiencing problems using a Word document with form fields. It
seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
I assume that you have locked the forms? The fields don't work as intended
unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
Thanks for the information. I'll give it a try!
We had to unlock the forms because the first problem we discovered is that there are links within some of the content and the hyperlink button is greyed out when the lock is on. It's easy for us to remember to turn off and on the lock as needed, but our end users need something simple. We are getting a million support calls! Thanks again! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
OK, I tried the macros and they worked to remove the form field, but they
also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
In that case, you can unlink the fields by selecting the document (Ctrl+A)
and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
Wow - that did work! Now, is there a macro to perform that command on all my
documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
I have no VBA expertise, either. There are macros to Find and Replace in a
batch of files at http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm, http://www.gmayor.com/batch_replace.htm, and http://gregmaxey.mvps.org/VBA_Find_And_Replace.htm. These could probably be adapted. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#8
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
To do this with a macro, the basic code would be -
Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#9
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
I am soooo close to getting this thanks to both of you!
Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#10
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
Oops!
Sorry, my fault, I made some changes in the e-mail editor and didn't bother to check. Scrub the last version and use the following. You don't need any document open when you run the macro, as it will close any open document as part of the process. Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: I am soooo close to getting this thanks to both of you! Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub See http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: We are experiencing problems using a Word document with form fields. It seems that you have to click inside the gray box, then use your arrow key to go to the text you want to change then begin typing ...instead of just being able to click in the appropriate place in the box and type. Our end users are frustrated with this, so we would like to simply remove the form fields from the word documents completely, but leave the text. There are a number of documents, so we need an easy way to do it. Any ideas? |
#11
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
OK - I'll try this one. How does the macro know which folder my documents
are stored in if I don't have one open or direct it to the right folder in some way? "Graham Mayor" wrote: Oops! Sorry, my fault, I made some changes in the e-mail editor and didn't bother to check. Scrub the last version and use the following. You don't need any document open when you run the macro, as it will close any open document as part of the process. Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: I am soooo close to getting this thanks to both of you! Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld |
#12
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
Now when I run the macro, I get the Copy dialog box. I browse to the folder
where my files are stored and click Open. The dialog box then closes, but nothing has happened....not sure what I'm doing wrong! "Graham Mayor" wrote: Oops! Sorry, my fault, I made some changes in the e-mail editor and didn't bother to check. Scrub the last version and use the following. You don't need any document open when you run the macro, as it will close any open document as part of the process. Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: I am soooo close to getting this thanks to both of you! Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld |
#13
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
The macro uses the Copy dialog to select the folder with the assembly of
files. When you click Open, the macro looks in that field for Word '.doc' files, which it opens in turn, unprotects the form (provided it has no password - or you'll get an error) then unlinks any form fields in the document, which it saves and closes. The macro should be seen running in that it quickly opens and closes each file. I take it you do have *.doc format files in that folder? I will be out for most of the day, but if you want to send me a sample document via the link on my web site, I will see if I can locate the problem when I return. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Now when I run the macro, I get the Copy dialog box. I browse to the folder where my files are stored and click Open. The dialog box then closes, but nothing has happened....not sure what I'm doing wrong! "Graham Mayor" wrote: Oops! Sorry, my fault, I made some changes in the e-mail editor and didn't bother to check. Scrub the last version and use the following. You don't need any document open when you run the macro, as it will close any open document as part of the process. Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: I am soooo close to getting this thanks to both of you! Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld |
#14
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
Aha - that's the problem then. All the files are saved as a web page. They
have either the .htm or .mht extension. "Graham Mayor" wrote: The macro uses the Copy dialog to select the folder with the assembly of files. When you click Open, the macro looks in that field for Word '.doc' files, which it opens in turn, unprotects the form (provided it has no password - or you'll get an error) then unlinks any form fields in the document, which it saves and closes. The macro should be seen running in that it quickly opens and closes each file. I take it you do have *.doc format files in that folder? I will be out for most of the day, but if you want to send me a sample document via the link on my web site, I will see if I can locate the problem when I return. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Now when I run the macro, I get the Copy dialog box. I browse to the folder where my files are stored and click Open. The dialog box then closes, but nothing has happened....not sure what I'm doing wrong! "Graham Mayor" wrote: Oops! Sorry, my fault, I made some changes in the e-mail editor and didn't bother to check. Scrub the last version and use the following. You don't need any document open when you run the macro, as it will close any open document as part of the process. Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: I am soooo close to getting this thanks to both of you! Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" |
#15
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
If you change the line
myFile = Dir$(PathToUse & "*.doc") to myFile = Dir$(PathToUse & "*.htm") it will open htm files instead of doc. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Aha - that's the problem then. All the files are saved as a web page. They have either the .htm or .mht extension. "Graham Mayor" wrote: The macro uses the Copy dialog to select the folder with the assembly of files. When you click Open, the macro looks in that field for Word '.doc' files, which it opens in turn, unprotects the form (provided it has no password - or you'll get an error) then unlinks any form fields in the document, which it saves and closes. The macro should be seen running in that it quickly opens and closes each file. I take it you do have *.doc format files in that folder? I will be out for most of the day, but if you want to send me a sample document via the link on my web site, I will see if I can locate the problem when I return. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Now when I run the macro, I get the Copy dialog box. I browse to the folder where my files are stored and click Open. The dialog box then closes, but nothing has happened....not sure what I'm doing wrong! "Graham Mayor" wrote: Oops! Sorry, my fault, I made some changes in the e-mail editor and didn't bother to check. Scrub the last version and use the following. You don't need any document open when you run the macro, as it will close any open document as part of the process. Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: I am soooo close to getting this thanks to both of you! Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub You may even be able to ypdate all the forms at once if you put them in a folder and run the following macro, though this would only work if none of the forms were password protected or if they were not all protected with the same password which you would enter between the quotes at: ActiveDocument.Unprotect Password:="" I recommend you test with copies of the documents!!! Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" |
#16
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
Excellent! It's working now. Thanks so much - this will save us a ton of
time! "Graham Mayor" wrote: If you change the line myFile = Dir$(PathToUse & "*.doc") to myFile = Dir$(PathToUse & "*.htm") it will open htm files instead of doc. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Aha - that's the problem then. All the files are saved as a web page. They have either the .htm or .mht extension. "Graham Mayor" wrote: The macro uses the Copy dialog to select the folder with the assembly of files. When you click Open, the macro looks in that field for Word '.doc' files, which it opens in turn, unprotects the form (provided it has no password - or you'll get an error) then unlinks any form fields in the document, which it saves and closes. The macro should be seen running in that it quickly opens and closes each file. I take it you do have *.doc format files in that folder? I will be out for most of the day, but if you want to send me a sample document via the link on my web site, I will see if I can locate the problem when I return. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Now when I run the macro, I get the Copy dialog box. I browse to the folder where my files are stored and click Open. The dialog box then closes, but nothing has happened....not sure what I'm doing wrong! "Graham Mayor" wrote: Oops! Sorry, my fault, I made some changes in the e-mail editor and didn't bother to check. Scrub the last version and use the following. You don't need any document open when you run the macro, as it will close any open document as part of the process. Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: I am soooo close to getting this thanks to both of you! Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False |
#17
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Can I remove form fields from my document but keep the text?
Glad we got there in the end
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Excellent! It's working now. Thanks so much - this will save us a ton of time! "Graham Mayor" wrote: If you change the line myFile = Dir$(PathToUse & "*.doc") to myFile = Dir$(PathToUse & "*.htm") it will open htm files instead of doc. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Aha - that's the problem then. All the files are saved as a web page. They have either the .htm or .mht extension. "Graham Mayor" wrote: The macro uses the Copy dialog to select the folder with the assembly of files. When you click Open, the macro looks in that field for Word '.doc' files, which it opens in turn, unprotects the form (provided it has no password - or you'll get an error) then unlinks any form fields in the document, which it saves and closes. The macro should be seen running in that it quickly opens and closes each file. I take it you do have *.doc format files in that folder? I will be out for most of the day, but if you want to send me a sample document via the link on my web site, I will see if I can locate the problem when I return. -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Now when I run the macro, I get the Copy dialog box. I browse to the folder where my files are stored and click Open. The dialog box then closes, but nothing has happened....not sure what I'm doing wrong! "Graham Mayor" wrote: Oops! Sorry, my fault, I made some changes in the e-mail editor and didn't bother to check. Scrub the last version and use the following. You don't need any document open when you run the macro, as it will close any open document as part of the process. Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: I am soooo close to getting this thanks to both of you! Graham, when I run the macro, I get a compile error: End With without With . It highlights the last "End With". Just to make sure I'm running it right...I put all the documents in the same folder on my server, then I opened one of them in Word and clicked the button on the toolbar to run the macro. Thanks so much! "Graham Mayor" wrote: To do this with a macro, the basic code would be - Sub ChangeFFields() Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld With ActiveWindow.View .ShowFieldCodes = False End With CommandBars("Forms").Visible = False End Sub Which will unlink the form fields and retain the content. As a batch process, with the same provisos as befo Sub BatchFixFields() Dim myFile As String Dim PathToUse As String Dim MyDoc As Document Dim iFld As Integer Dim bProtected As Boolean 'Unprotect the file If ActiveDocument.ProtectionType wdNoProtection Then bProtected = True ActiveDocument.Unprotect Password:="" End If With Dialogs(wdDialogCopyFile) If .Display 0 Then PathToUse = .Directory Else MsgBox "Cancelled by User" Exit Sub End If End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If If Left(PathToUse, 1) = Chr(34) Then PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2) End If myFile = Dir$(PathToUse & "*.doc") While myFile "" Set MyDoc = Documents.Open(PathToUse & myFile) ActiveWindow.View.ShowFieldCodes = True For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) If .Type = wdFieldFormTextInput Then .Unlink End If End With Next iFld CommandBars("Forms").Visible = False ActiveWindow.View.ShowFieldCodes = False End With MyDoc.Close SaveChanges:=wdSaveChanges myFile = Dir$() Wend End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org BonnieK wrote: Wow - that did work! Now, is there a macro to perform that command on all my documents in a folder without opening each one? I don't work very much with macros.... "Suzanne S. Barnhill" wrote: In that case, you can unlink the fields by selecting the document (Ctrl+A) and pressing Ctrl+Shift+F9, but see also http://word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. "BonnieK" wrote in message ... OK, I tried the macros and they worked to remove the form field, but they also removed all the text that resided in the form fields. We just want to cut the text out of the form fields - remove the fields - and paste the text back in the right place in the document as plain text.... Thanks! "Graham Mayor" wrote: I assume that you have locked the forms? The fields don't work as intended unless the form is locked. In order to remove the form fields, you first need to unlock the form. The following macro will then remove any form fields in the document. Sub RemoveFFields() ActiveDocument.ActiveWindow.View.ShowFieldCodes = True With Selection .HomeKey Unit:=wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^d FORMTEXT" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .Execute replace:=wdReplaceAll End With End With ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub If you are changing the use of the document, you might want to consider changing the form fields to macrobutton place markers. eg Sub ChangeFFields() ActiveWindow.View.ShowFieldCodes = True Dim oRng As Range Dim iFld As Integer For iFld = ActiveDocument.Fields.Count To 1 Step -1 With ActiveDocument.Fields(iFld) .Code.Text = replace(.Code.Text, "FORMTEXT", "MACROBUTTON NoMacro Enter Text") .Update End With Next iFld With ActiveWindow.View .FieldShading = wdFieldShadingAlways .ShowFieldCodes = False End With CommandBars("Forms").Visible = False |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Activating a document that has visual basic text and form fields | Microsoft Word Help | |||
Remove background highlighting form merge fields | Mailmerge | |||
Text form fields and merge document | New Users | |||
Form text fields are disappearing during a merge to new document. | Mailmerge | |||
Email a protected document that contains Text Form Fields | New Users |