• Copy a cell and not a table? (Word 2003)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Copy a cell and not a table? (Word 2003)

    Author
    Topic
    #441315

    Good Morning,

    I have attached a form that I have been working on forever bash . I used the record a macro feature to automate a few of the things I need this form to do.
    1. When the user “tabs” out of the notes form field I would like another page added. The add “a page macro” (which I think I got from this site clapping ) works perfectly.
    2. I need the cursor to return to the notes section on the 2nd page. I created the “move it” macro to do just that.
    3. I need only the title, date, notes section, and confidential information on the second page. I created the “merge” macro to delete and merge all the other fields. For some reason this macro also adds another page.
    All the macros ‘work’ on their own, but I need them to all be one function when the user tabs out of the notes section on the first page. I don’t know how to combine all the macros into one.

    I feel like I am going about this the completely wrong way, so any help at all would be appreciated. My dream would be for the form to work like this:
    The user would fill in all the required information and complete the notes section.
    When the user got to the bottom of the notes section they could tab out to add another page if needed.
    The 2nd page would only have the title, date, notes, and confidential information sections.

    Thank you for your help!

    Viewing 0 reply threads
    Author
    Replies
    • #1059381

      Is this form to be used within your organization, or is it intended to be sent out to people outside your organization?

      • #1059383

        Thanks for responding Hans.

        This form will be completed by members of my organization but the completed (printed) form will be forwarded to people outside the organization.

        Warm Regards,

        SME

        • #1059385

          If the form is to be completed within your organization, I would recommend the following:
          – Save your form as a template (.dot).
          – Insert a page break at the end of the first page.
          – Create the second page table manually.
          – Select the page break together with the second page table, and create an AutoText entry for it. Make sure that it is saved in the template, not in your Normal.dot.
          – Now delete the page break and table again.
          – Use the add_page macro you already have to unprotect the document, insert the AutoText entry and to protect the document again.

          To insert an AutoText entry using code:

          ActiveDocument.AttachedTemplate.AutoTextEntries("NameOfEntry").Insert _
          Where:=Selection.Range, RichText:=True

          This way, your code doesn’t have to do any manipulation of the table or its cells, it only inserts the existing AutoText entry.

          • #1059396

            Hi Hans,

            Great suggestion, but I don’t think I am implementing it properly because I am getting an error message:
            Run Time Error 5941 The requested member of the collection does not exist. or
            Run Time Error 5981 Cannot open macro storage

            My add a page code now looks like this:

            Sub add_page()

            If ActiveDocument.ProtectionType wdNoProtection Then
            ActiveDocument.Unprotect Password:=”summer”
            End If

            Dim pass
            Dim table_num As Integer
            Dim i As Integer

            With ActiveDocument.Tables(table_num)
            .Select
            Selection.Fields.Update
            End With

            ActiveDocument.AttachedTemplate.AutoTextEntries(“AddPage”).Insert _
            Where:=Selection.Range, RichText:=True

            If ActiveDocument.ProtectionType = wdNoProtection Then
            ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
            NoReset:=True
            End If

            End Sub

            I have saved the form as a document template. This is my first time working with Auto Text. Your guidance is appreciated.

            • #1059401

              Perhaps you didn’t name the AutoText entry “AddPage”.

              I have attached a (zipped) sample template with an AutoText entry.

            • #1059407

              Thank you both for your suggestions.

              Hans, you were correct in your assumption that I did not have my Auto Text entry named “Add Page”.

              I’m going to try and apply my new knowledge to the form and will post with an update.

              Thank you!

              Warm Regards,

              Summer

            • #1060428

              Good Afternoon,

              Everything works perfectly, in document form. But when I save it to a template the AddTable macro/auto text gives me an error message. I think it’s because the auto text is saved to my Normal.dot and not the template. When I try to copy the auto text over to the template I get an error message “Cannot attach document to protected template” I can only assume it is referring to the normal.dot.

              I tried recreating the form and the auto text, but I can’t get the auto text to save any where else but the normal.dot. I need everything to work in a template and for that template to be mobile.

              Please tell me what I am doing wrong.

              Warm Regards,

              Summer

            • #1060431

              Your template is protected for forms. If you want to modify it, for example add an AutoText entry, you must temporarily unprotect it, apply the changes, then protect it again before saving it.

            • #1060437

              After you said that it actually worked cool .

              But when I unprotect the template and then add the auto text and reprotect the template, I can’t resave the template without losing the auto text. Any Suggestions?

              Warm Regards,

              Summer

            • #1060471

              Protecting the template shouldn’t cause the AutoText entry to be lost. Are you absolutely sure you stored it in the template?

            • #1060575

              Good morning,

              I made sure the auto text was attached to the document and then protected the document and saved it as a template. When I open the template and run the macro I get an error message that the auto text cannot be found. I unprotect the template and manually add in the macro and then reprotect the document. But when I go to resave the template I have to rename it and the auto text/macro does not follow.

              doh

              Warm Regards,

              Summer

            • #1060579

              You cannot save AutoText in a document. So you must save as a template first and then add the AutoText entry.

            • #1059402

              You have the line
              With ActiveDocument.Tables(table_num)

              You haven’t set the value of table_num, so it will be using an initial value of 0, and since ActiveDocument.Tables(0) doesn’t exist you get the error. Try setting table_num to the correct value.

              StuartR

        • #1059395

          I forgot to mention: make the template available to the users either by letting them copy it to their User Templates folder, or by placing it in a shared network folder.
          When they need the form, they can create a new document based on the template. The macros and AutoText entry will be available in the new document.

    Viewing 0 reply threads
    Reply To: Copy a cell and not a table? (Word 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: