1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Runtime Error 4120 in Word 2007 macro

Discussion in 'Business Applications' started by Frankwlc, Nov 18, 2011.

Thread Status:
Not open for further replies.
  1. Frankwlc

    Frankwlc Thread Starter

    Joined:
    Sep 2, 2010
    Messages:
    9
    I have built a protected form in Word 2007 but the eventual user wants the facility to extend the number of rows 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. 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 Files:

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1027342

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice