Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Word ActiveX textbox with VBA code from Excel

Status
Not open for further replies.

TDugan

Technical User
Oct 12, 2012
18
0
0
US
I have VBA code in excel and as part of that I launch a document in Word and populate ActiveX textboxes with information that was populated in the Excel userform.

However, in some instances, I want the code to delete the ActiveX textbox instead of populating it. Can anyone tell me how to accomplish this task.

Here is my code. It is the "No" option that I am referencing that doesn't work.

If frmRLRP.cboPrivilege.Value = "Yes" Then
wdDoc.txtPrivilege.Text = "Privilege of Commutation shall be granted to my beneficiary(ies)."
ElseIf frmRLRP.cboPrivilege.Value = "No" Then
wdDoc.txtPrivilege.DeleteShape
End If

I would appreciate any help.
 
hi,

Never liked the idea of deleting an object, as there are other ramification, and unintended consequences.

How about just making it invisible?
Code:
'
    If frmRLRP.cboPrivilege.Value = "Yes" Then
        wdDoc.txtPrivilege.Text = "Privilege of Commutation shall be granted to my beneficiary(ies)."
    ElseIf frmRLRP.cboPrivilege.Value = "No" Then
        wdDoc.txtPrivilege.Visible = False
    End If

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thanks. My issue with that is that I have information underneath of it so just making it invisible will make it look like a gap in the document. Any other suggestions?
 
Would this work?
Code:
If frmRLRP.cboPrivilege.Value = "Yes" Then
   wdDoc.txtPrivilege.Text = "Privilege of Commutation shall be granted to my beneficiary(ies)."
ElseIf frmRLRP.cboPrivilege.Value = "No" Then
   wdDoc.txtPrivilege.Delete
End If
I'd guess that this is not a Shape object but an InLineShape object if that makes any difference.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Hi,

I tried your suggestion of just Delete instead of DeleteShape. I received the following error message:
Run-time error '5'. Invalid procedure call or argument.
 

for an InlineShape object (my guess)
Code:
wdDoc.txtPrivilege.InlineShape.Delete

for a Shape object
Code:
wdDoc.txtPrivilege.Shape.Delete



Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top