PDA

View Full Version : [SOLVED:] Macro that automatically replace theserForm info into the text.



sb003848
09-26-2013, 08:21 AM
Hello,

I created a file in which a UserForm is shown once the file is opened. The userform looks like this:

http://www.vbaexpress.com/forum/attachment.php?attachmentid=10441&d=1376506226

I wish to use the info entered in the 7 fields in order to change the the red text in the following text (HTML code):

<UL class=videos>
<LI>
<DIV class="gallery clearfix wmv_play"><A href="VIDEO_LINK?width=320&amp;height=240&amp;controls=1" rel=prettyPhoto[movie]><IMG style="MARGIN-TOP: 12px" class=video-screenshot border=0 alt="Visionner la vidéo" src="VIDEO_STILL" width=200 height=113> </A></DIV>
<DIV style="WIDTH: 300px" class=video-details>
<P class=video-title>VIDEO_TITLE</P>
<P class=video-trans></P>
<DIV class="gallery clearfix wmv_play"><A href="VIDEO_LINK?width=320&amp;height=240&amp;controls=1" rel=prettyPhoto[movie]>Visionner la vidéo</A> &nbsp;VIDEO_MIN mins&nbsp; VIDEO_SEC sec <BR><A href="Lire'>VIDEO_RELATED_ARTICLE">Lire l'article complet</A>
<P class=video-date>VIDEO_DATE</P></DIV></DIV></LI></UL>

The data in red must be replaced by the data found in the form.

VIDEO_LINK needs to be replace by the value found in TextBox1
VIDEO_STILL needs to be replace by the value found in TextBox2
VIDEO_TITLE needs to be replace by the value found in TextBox3
VIDEO_MIN needs to be replace by the value found in TextBox4
VIDEO_SEC needs to be replace by the value found in TextBox5
VIDEO_RELATED_ARTICLE needs to be replace by the value found in TextBox6
VIDEO_DATE needs to be replace by the value found in TextBox7

Any ideas how I can create such a Macro?

Thanks for your time

sb003848
09-26-2013, 10:17 AM
Well, after looking at a few things on Google and trying a few things on my own, I was able to do it. It's probably not the proper way but it works so I'm happy...

I simply assigned the following macro to my OK button on my UserForm:

Sub CommandButton1_Click()
With Selection.Find
.Text = "VIDEO_LINK"
.Replacement.Text = FormDetail.TextBox1
.Execute Replace:=wdReplaceAll
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Find
.Text = "VIDEO_STILL"
.Replacement.Text = FormDetail.TextBox2
.Execute Replace:=wdReplaceAll
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Find
.Text = "VIDEO_TITLE"
.Replacement.Text = FormDetail.TextBox3
.Execute Replace:=wdReplaceAll
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Find
.Text = "VIDEO_MIN"
.Replacement.Text = FormDetail.TextBox4
.Execute Replace:=wdReplaceAll
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Find
.Text = "VIDEO_SEC"
.Replacement.Text = FormDetail.TextBox5
.Execute Replace:=wdReplaceAll
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Find
.Text = "VIDEO_RELATED_ARTICLE"
.Replacement.Text = FormDetail.TextBox6
.Execute Replace:=wdReplaceAll
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Find
.Text = "VIDEO_DATE"
.Replacement.Text = FormDetail.TextBox7
.Execute Replace:=wdReplaceAll
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Unload Me
End Sub