Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-21-2011, 02:32 AM
Frankwlc Frankwlc is offline Runtime Error 4120 in Word 2007 macro Windows XP Runtime Error 4120 in Word 2007 macro Office 2007
Novice
Runtime Error 4120 in Word 2007 macro
 
Join Date: Nov 2011
Posts: 5
Frankwlc is on a distinguished road
Default Runtime Error 4120 in Word 2007 macro

I have built a protected form in Word 2007 but the eventual user wants the facility to extend the number of rows themselves in certain tables as the 'standard' amout I have set out may not be sufficient for their needs which can vary from form to form. I knew I would have to utilise a macro to do this but this is new territory for me so I did some Googling and found a suitable macro script on another forum (see script at end of this post). I tested this out on a dummy document using a keyboard shortcut and it worked fine but when I use the macro on the proper form I get a Runtime error, even though the macro does add the extra row. The proper form is not complex as it only consists of the normal protection with unprotected text fields although it is around 10 pages in length. There are no other macros that might cause a conflict.
When I check the debug info, the line oFld(i).Result = "" is highlighted as being the problem.
I have added the error and debug info below, along with the macro script.
Hoping someone can shed some light on this for me.

================================================== =========================

Sub AddARow()
Dim i As Integer
Dim bProtected As Boolean


Dim sNewRow As String
Dim oFld As FormFields
sNewRow = InputBox("Insert New Row", "New Row", "No")
If Left(UCase(sNewRow), 1) <> "N" Then
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
With Selection
.SelectRow
.Copy
.Paste
.SelectRow
Set oFld = Selection.Range.FormFields
For i = 1 To oFld.Count
oFld(i).Result = ""
Next
End With
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End If
End Sub
Attached Images
File Type: jpg macro_error_1a.jpg (20.0 KB, 4 views)
File Type: jpg macro_error_1.jpg (84.2 KB, 4 views)
Reply With Quote
  #2  
Old 11-21-2011, 02:47 AM
macropod's Avatar
macropod macropod is offline Runtime Error 4120 in Word 2007 macro Windows 7 64bit Runtime Error 4120 in Word 2007 macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,065
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Hi Frank,

Does the row you're actually adding contain formfields and, if so, what kind of formfields are they?

You might also look at the discussions at:
http://www.tech-archive.net/Archive/.../msg00682.html
and:
http://www.eggheadcafe.com/microsoft...ted-table.aspx
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-22-2011, 02:34 AM
Frankwlc Frankwlc is offline Runtime Error 4120 in Word 2007 macro Windows XP Runtime Error 4120 in Word 2007 macro Office 2007
Novice
Runtime Error 4120 in Word 2007 macro
 
Join Date: Nov 2011
Posts: 5
Frankwlc is on a distinguished road
Default

Paul - thanks for the answer which I wasn't able to respond to yesterday.

I've had another look at the form and did some further testing. The error only appears when trying to add a row to one particular table in the form. This table has three coulmns with normal text-only form fields but a fourth column has a drop-down box option in each row so presumably it is this which is causing the problem?
Reply With Quote
  #4  
Old 11-23-2011, 03:04 AM
Frankwlc Frankwlc is offline Runtime Error 4120 in Word 2007 macro Windows XP Runtime Error 4120 in Word 2007 macro Office 2007
Novice
Runtime Error 4120 in Word 2007 macro
 
Join Date: Nov 2011
Posts: 5
Frankwlc is on a distinguished road
Default

Things have moved on a bit from my original problem. I dispensed with the dropdown option in the table which gets rid of the RunTime error but I now have the problem of macro disabling/enabling. I was totally oblivious to Microsoft's security stance on macros as I successfully did all the macro testing on my own PC but, of course, as soon as I send the form to another person their copy of Word blocks all macros and I have discovered that even if they select the option to run macros it still won't work on their PC. Even if the macro were to work via this option I feel this is kind of defeating the purpose of having the macro in the first place as the plan was to allow staff, who may not be especially familiar with Word anyway, the simplest way of adding additional rows to the form.
Reply With Quote
  #5  
Old 11-26-2011, 12:16 AM
macropod's Avatar
macropod macropod is offline Runtime Error 4120 in Word 2007 macro Windows 7 64bit Runtime Error 4120 in Word 2007 macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,065
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Hi Frank,

For security reasons, there is no way to enforce the running of a macro. Nevertheless, if the form recipient enables macros on their PC (installation of the vba components as part of Word's setup can be denied) and allows it to run, I can see no reason why the code shouldn't run on just one PC.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 11-28-2011, 01:54 AM
Frankwlc Frankwlc is offline Runtime Error 4120 in Word 2007 macro Windows XP Runtime Error 4120 in Word 2007 macro Office 2007
Novice
Runtime Error 4120 in Word 2007 macro
 
Join Date: Nov 2011
Posts: 5
Frankwlc is on a distinguished road
Default

Thanks Paul. Since my last post the manager who requested the form has seen a PDF example in use with another company that has 'sexy' Add and Delete Row buttons and she wants me to create one like that!
It would be done in Adobe Live Cycle Designer, which I do have as part of Acrobat Professional, but I just need to go away and learn how to use it now.

Thanks for your help anyway.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Error 4120 in Word 2007 macro Word 2007 & Outlook 2007 - Odd Error Message EllieW Word 3 08-16-2011 11:27 AM
Runtime Error 4120 in Word 2007 macro Runtime error 91 waldux Word VBA 1 03-04-2011 11:25 PM
MS Word 2007 error when trying to upload .doc or .docx to a webpage heretical1 Word 0 10-06-2010 12:20 PM
Runtime error 5487 - Word cannot complete the save to to file permission error franferns Word 0 11-25-2009 05:35 AM
Receive error cannot open this form because an error occurred in BCM 2007 bornhusker Outlook 0 06-01-2009 10:28 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 03:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft