Consulting

Results 1 to 6 of 6

Thread: Prevent Form from being deleted

  1. #1
    VBAX Regular
    Joined
    Aug 2012
    Location
    France
    Posts
    13
    Location

    Prevent Form from being deleted

    Hi,

    I have an issue with a form button box which in some case end up being deleted from the word document depending on the updates made to the document though the macro.
    Initially I though of protecting the form in the macro before executing the rest of the code and unprotect it again. However, I have not been able to find such code.
    Alternatively I though of coping the form and pasting same after execution of the marco. This seem to work if you know the name of the form.
    Say, I rename my "Control 63" to "UpdateButton" then next time I open the word file the ActiveDocument.Shapes("UpdateButton") cannot be found. My shape has been renamed to "Control 64".

    Any suggestions? Protections of form, or dynamically identifying name of form or others?
    I might be an idiot at programming but this one I have not been able to google the answer.

    Thanks in advance
    Alex

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Not sure what you mean by "form button box".

    Why would it be deleted? If something is being deleted that should not be, this sounds like a lack of good error trapping. Hard to say. Can you post code that both does, and does not, delete what you do not want deleted?

    Copying and repasting back in is a posibility I suppose, but it sure is poor practice. It adds potential for errors.
    Say, I rename my "Control 63" to "UpdateButton" then next time I open the word file the ActiveDocument.Shapes("UpdateButton") cannot be found. My shape has been renamed to "Control 64".
    I do not follow this at all.

    1. rename Control 63 to UpdateButton
    2. I assume the file is saved.
    3. if reopened, WHY - if it is renamed UpdateButton - is it renamed Control 64???? It is not going to be renamed Control 64 unless YOU did that.

    I am missing something.

    BTW: it is a good idea to not have any objects named Control 63. It is not a helpful name.

  3. #3
    VBAX Regular
    Joined
    Aug 2012
    Location
    France
    Posts
    13
    Location
    Hi

    OK I will try to explain myself a bit better.
    I have several Command Buttons (ActiveX controls) inserted into my document used for updating the tables in the document.
    Side Note! because I don’t want to have these printed there are located to the right hand side of the page margin.
    Anyway, if this Command button is located to the right of a table where lines are being deleted through a command like table(x).rows(y).delete then the command button is also deleted. Naturally I could just move Command button elsewhere but I would not call that a fix as there are many users of the document.
    As I mentioned before I have tried to protect the Command button but this option does not appear in the Properties setup (right click) or for any code that I could find.
    Secondly, If I name the Command button in the Properties setup the name will not be recognised in the code. Example, say I name the button "UpdateSomething" then when I try to say temporarily delete to Button I cannot refer to the Button like this: ActiveDocument.Shapes("OperatorButton").Select
    The actual name of the Button will be "Control <no>" . Even if I rename the control through the macro to "UpdateSomething" it will continue to work only for as long as I don’t shut down my document. When open again, the name format will be back to "Control <xx>".

    Does it make sence now?

    regards
    Alex

  4. #4
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    You probably can't google an answer because it sounds like a pretty strange design specification you're describing.

    I think you're going to need to post a sample document of what you're doing.

    Because I don't understand why you need activeX controls at all. Why don't you just add some toolbar buttons or some ribbon/QAT buttons? Then you don't have to worry about losing access to your macros because the end-user hits the delete key somewhere in the document...

    Apart from that, you could try using frames or something, but at the end of the day... if it's in the document, the user can delete it... unless the document is protected. But if the document isn't currently protected, I suspect that solution would be more onerous than you simply learning a bit about how to do a proper user interface.

    Please note: if you have asked this same question elsewhere, this is called cross-posting, and you should provide links so you don't have multiple people at different forums all spending time for free trying to help you. Don't take offense, I tend to say this to new users

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I concur. Post a sample file with the code.

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by AAhrenst
    I have several Command Buttons (ActiveX controls) inserted into my document used for updating the tables in the document.
    Side Note! because I don’t want to have these printed there are located to the right hand side of the page margin.
    Anyway, if this Command button is located to the right of a table where lines are being deleted through a command like table(x).rows(y).delete then the command button is also deleted. Naturally I could just move Command button elsewhere but I would not call that a fix as there are many users of the document.
    You could put the ActiveX buttons into a narrow table that you position in the margin, alongside the table in the body of the document. That way, deleting the table in the body of the document will have no effect on the ActiveX controls. Furthermore, if you use a macro to do the printing, you could add code to temporarily move the 'margin' table right off the page at print time.

    See attached.
    Attached Files Attached Files
    Last edited by macropod; 08-09-2012 at 12:14 AM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •