How do I delete a row?

  • Question is as follows:


    When a reference cannot be provided, is it possible for a user to click "reference" and then it deletes that row?


    Attachment in first post


    P.S. It has to be done in Word, using Excel is not an option.

  • Re: How do I delete a row?


    Quote from cytop;752211

    Why bother with a macro when a mouse click and 1 keypress will do it...?


    Good question.


    It may be worth mentioning that it will be a template letter within Word.


    Sometimes the field will be needed, other times it will not be.


    Sending out a letter when the field is not needed but still present makes it look unprofessional

  • Re: How do I delete a row?


    And how is the letter produced...?


    Information in your post is very limited - all you will get is general suggestions which is not what you want. Consider taking the time to fully explain the scenario...

  • Re: How do I delete a row?


    Quote from cytop;752215

    And how is the letter produced...?


    Information in your post is very limited - all you will get is general suggestions which is not what you want. Consider taking the time to fully explain the scenario...


    Apologies.


    It's exactly like the attachment.


    Once the template is locked, the end users can only type in the grey fields.


    The problem I have is if there isn't a reference to enter, you remove the text then the letter looks unprofessional as there will be a random gap between Address Line 5 and Dear Sir/Madam


    For this reason I was hoping that if "You double click ‘Reference’ and then it deletes that entire row so ‘Dear Sir/Madam’ and ‘I am writing to’ move up a row"

  • Re: How do I delete a row?


    There are a couple of things that complicate this.


    Word does not have a 'Document_DoubleClick' event. It does have an Application Double Click (which works on the Active Document, perversely enough) but it will take quite a bit of extra programming to implement it using a class module with a reference to the Word application using 'WithEvents' - too much bother for something as trifling as this (Apologies, but that is my opinion).


    Also, you have 'Reference' as a form field - that hardly matters as you can't double click it but it does not fit into your intended structure so that should be changed to normal text.


    You can try the following, but you need to change the 'Soft' carriage returns before and after the line with 'hard' carriage returns (Leave a soft carriage return at the end of the line itself). This is needed as the code below deletes a complete paragraph.


    Code
    Sub x()
    
    
       If ActiveDocument.FormFields("Text2").Range.Text = vbNullString Then
          ActiveDocument.FormFields("Text2").Range.Select
          Selection.Paragraphs(1).Range.Delete
       End If
          
    End Sub


    The easiest thing to do with that is to assign a quick key to the macro - I'll leave you to figure that one - past my bedtime now so I'm off...

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!