Hello!
I hope someone can take a look at my examples and give me some idea about what I'm doing wrong...or if it's even possible to do what I want:) Please see the attached file. It's a short example of the document I'm using.
forum.ozgrid.com/index.php?attachment/35476/
Problem: I have a macro (below), which doesn't work, since after restricting the document it "turns off" find function. I need help with changing my macro (the part in red color below) find fucntion from findind a word to finding a form tag and enterting the text based on what's entered in a pop up box.
So, let's say the tag for the first form is businessname, then macro should have to something like
Dim objCC As ContentControl
Dim myTag As String
myTag = "businessname"
'following by the part I don't know:)
So i need the macro to find that tag and than edit that text form based on the info entered in the InputBox. Does it make sence?
Note about the attachment: I wasn't able to attach the document in docx format, so I changed it to doc, which removed editable fields aka content controls
Sub example()
'
' email Macro
'business name replacement
Selection.find.ClearFormatting
With Selection.find
.Text = "INSERT BUSINESS NAME"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'pop-up box
Dim businessname, msgbox1 As Variant
businessname = InputBox("Enter Business Name")
'replaces found text with the text entered in the input box
Selection.find.Execute
Selection.TypeBackspace
Selection.TypeText Text:=businessname
If businessname = Empty Then
businessname = InputBox("This field cannot be empty! Please enter the Business Name:")
Selection.find.ClearFormatting
With Selection.find
End With
Selection.find.Execute
Selection.TypeText Text:=businessname
If businessname = Empty Then
msgbox1 = msgbox("This field cannot be empty! Please reopen the document and try again")
ActiveDocument.ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
End
End If
End If
'MID replacement
Selection.find.ClearFormatting
With Selection.find
.Text = "MID"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'pop-up box
Dim mid As Variant
mid = InputBox("Enter ID")
'replaces found text with the text entered in the input box
Selection.find.Execute
Selection.TypeBackspace
Selection.TypeText Text:=mid
If mid = Empty Then
mid = InputBox("This field cannot be empty! Please enter the ID:")
Selection.find.ClearFormatting
With Selection.find
End With
Selection.find.Execute
Selection.TypeText Text:=mid
If mid = Empty Then
msgbox1 = msgbox("This field cannot be empty! Please reopen the document and try again")
ActiveDocument.ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
End
End If
End If
'pop up boxes end
End Sub
Display More