![]() |
|
#1
|
|||
|
|||
![]()
I use this macro to change specific text, but it doesnt work, when text is inside text boxes. If text is in table cell, then macro work fine. What I must change in code, that will affect text in text boxes too, not just in table cell?
This is code: Code:
Sub Podpisi() With ActiveDocument.Content.Find .Execute FindText:="blue", ReplaceWith:="Mr." & vbCr & "Adrian Tomc", _ Format:=True, Replace:=wdReplaceAll End With End Sub |
#2
|
|||
|
|||
![]()
You are in the wrong story range
Code:
Sub Podpisi() Dim oRng As Range Set oRng = ActiveDocument.StoryRanges(wdTextFrameStory) With oRng.Find .Execute FindText:="help", ReplaceWith:="Mr." & vbCr & "Adrian Tomc", _ Format:=True, Replace:=wdReplaceAll End With End Sub |
#3
|
|||
|
|||
![]()
Tnx for reply but it doesnt work.
I get Run-time error '5941' the requested member of the collection does not exist. Any ideas why? |
#4
|
|||
|
|||
![]()
Tnx for reply but it doesnt work.
I get Run-time error '5941' the requested member of the collection does not exist. Any ideas why? |
#5
|
||||
|
||||
![]()
That error is most likely saying that there aren't any text frames in the document you are running the macro on.
Perhaps you would like to post a document with your 'text box' so we can make a macro that works with what you actually have. Alternatively, the macro could be modified to work across every type of story range. The current code examples are specific to one range only.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
![]()
Here is my file. Tnx for helping.
|
#7
|
||||
|
||||
![]()
Those empty boxes look like embedded OLE objects. Is this really what you are working with?
They don't appear to be editable to me. How do YOU put text inside them?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
|||
|
|||
![]()
Those are ActiveX controls. Why are you using those?
Sub test() With TextBox1 .MultiLine = True .Text = Replace(TextBox1.Text, "blue", "Mr." & vbCr & "Adrian Tomc") End With With TextBox11 .MultiLine = True .Text = Replace(TextBox1.Text, "blue", "Mr." & vbCr & "Adrian Tomc") End With With TextBox12 .MultiLine = True .Text = Replace(TextBox1.Text, "blue", "Mr." & vbCr & "Adrian Tomc") End With End Sub |
#9
|
|||
|
|||
![]()
Thank you all for help.
|
#10
|
|||
|
|||
![]()
gmaxey, yours solution works perfect, but can you help me one more time?
How to replace text, no matter, if text is in TextBox1, 2 or 3? I will have multiple options of input text and replace every word with other text, so it is a little unpractical to assign all options to every text box. Macro shoud lookup for specific text in all textboxes and replace it. Is it possible? Last edited by Charles Kenyon; 03-30-2021 at 08:39 AM. |
#11
|
||||
|
||||
![]()
Can we convince you to use something other than ActiveX Controls?
You 'should' be using Content Controls for this task. Then the coding will be much simpler and extensible.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#12
|
|||
|
|||
![]()
Ok. Let me explain, what I want to do.
I must have 3 text fields, because I will use this for server based signing word documents. I dont care, what kind of text field. I use ActiveX controls, because I can mask their text like password with ***. If is this possible with Content controls, fine by me. But I dont know, how to do that. So...in macro I will have several "passwords" saved from several users. Now, 3 random users will type in textfields their passwords. I will not know, who and what. Macro must reveal their passwords and replace this "password" words with correct titles. For revealing passwords I use this code with checkbox: Code:
Private Sub CheckBox1_Click() TextBox1.PasswordChar = IIf(CheckBox1, "", "*") TextBox11.PasswordChar = IIf(CheckBox1, "", "*") TextBox12.PasswordChar = IIf(CheckBox1, "", "*") End Sub When passwords was revealed, I run macro, that will change this words to proper titles. Answer from gmaxey working fine, problem is, that I dont know who and in which textbox will write his password. So...Macro must be able to check this too. Before I use this code: Code:
Sub Podpisi() With ActiveDocument.Content.Find .Execute FindText:="winki", ReplaceWith:="V. d. strokovnega direktorja" & vbCr & "Valentina Winkler Skaza, dr. med., spec. psih.", _ Format:=True, Replace:=wdReplaceAll End With With ActiveDocument.Content.Find .Execute FindText:="mario123", ReplaceWith:="Pomočnik direktorja za področje zdravstvene nege " & vbCr & "Mario Dremšak, mag. manag., dipl. zn.", _ Format:=True, Replace:=wdReplaceAll End With With ActiveDocument.Content.Find .Execute FindText:="onsightclimb", ReplaceWith:="Bojan Strauss, ZT", _ Format:=True, Replace:=wdReplaceAll End With End Sub Now, I have solution from gmaxey, it working fine, but I have to assign all possible options to every box, right? Now, if anybody understand from my poor english, what I try to accomplish, can you help me? I dont care, if I use something else and not Activex? TnX |
#13
|
||||
|
||||
![]()
I don't understand why there needs to be multiple steps so my solution may not be what you wanted. I would approach this by making use of checkbox content controls and having a macro check the user logon name to determine how to expand the user details.
This approach then just expects the user to just check a box and then move their cursor in order to see their details replace the checkbox immediately. To me this is much simpler in terms of usability. I've attached a demo document showing how this is set up. The code that is being used in the file is Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean) Dim sUser As String, sID As String sID = Environ$("UserName") If aCC.Type = wdContentControlCheckBox Then If aCC.Checked Then sUser = ExpandUser(sID) If sUser <> "" Then aCC.Type = wdContentControlText aCC.MultiLine = True aCC.Range.Text = sUser End If End If End If End Sub Function ExpandUser(sID As String) As String Select Case sID Case "winki", "winkidelegate" ExpandUser = "V. d. strokovnega direktorja" & vbCr & "Valentina Winkler Skaza, dr. med., spec. psih." Case "mario123" ExpandUser = "Pomocnik direktorja za podrocje zdravstvene nege " & vbCr & "Mario Dremšak, mag. manag., dipl. zn." Case Else Application.StatusBar = "Not a recognised user: " & sID End Select End Function Sub ResetCheckBoxes() Dim aCC As ContentControl For Each aCC In ActiveDocument.SelectContentControlsByTag("Signed") aCC.Type = wdContentControlCheckBox aCC.Checked = False Next aCC End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#14
|
|||
|
|||
![]()
Thank you for that but this is not what I need. Thank you anyway.
I use this for signing documents. There are about 15 people, that sign documents. I place docunemt on server, send link and 3 workers, assign for sign document can acces to file. Nobody can not know for password of other. So...they just read document, if they agree with content, they must write their password in one of those 3 textboxes. Becouse of that, passwords must be masked. I can do that only with textboxes. I am documents admin. When I see all 3 password filled, I then with macro running, convert those 3 passwords to original titles. Macro will be locked and only I can run macro. My two codes in original post working perfect...problem is, that they dont work inside textboxes. And my solution have multiple steps. Now I search for solution just with one step and that will work with textboxes too. Is it possible or not? |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Gerrit | Word VBA | 6 | 02-20-2021 08:53 AM |
![]() |
ksigcajun | Word VBA | 6 | 04-06-2015 07:41 AM |
Safe Senders Doesnt work | Anil Kaul | Outlook | 0 | 11-16-2012 01:28 PM |
![]() |
rmw85 | Word VBA | 1 | 04-25-2012 01:02 PM |
![]() |
dukquaknoobhack | Office | 1 | 01-05-2012 03:43 PM |