I must say, this is a great site...you guys are on the ball with the answers. Now, let's see if I can get 2 for 2!
Best case scenario, I would like to have Word automatically parse certain strings of characters to an inline shape. But, I've been working on a macro that will just parse all these strings after the document is complete. The macro searches for all text matching strings listed in an outside file. Here's the bit of the code that I am having a "ByRef argument type mismatch" error on.
I am a total newb to VBA, so please be kind! I'm a php guy...if only I could use php code! :-D
The delimited list looks something like this:
"","Happy"
So, I have a sub EmotImage(strName, strSize) which inserts the correct image on the page.
here's the code for that:
So, looking at all that crap that I'm probably doing totally wrong...can someone help me out?
Thanks!!!
Matt
Best case scenario, I would like to have Word automatically parse certain strings of characters to an inline shape. But, I've been working on a macro that will just parse all these strings after the document is complete. The macro searches for all text matching strings listed in an outside file. Here's the bit of the code that I am having a "ByRef argument type mismatch" error on.
I am a total newb to VBA, so please be kind! I'm a php guy...if only I could use php code! :-D
Code:
Sub ParseSmileys()
' Set options for the find-replace function for all of this type
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.MatchCase = True
.Wrap = wdFindStop
.MatchWildcards = False
.MatchWholeWord = True
End With
' Open the file containing the comma/quotation mark delimited list
Open "\\Server\IT Files\Macros\Emoticons\Smileys.txt" For Input As #1
' Loop through to the end of the file.
Do While Not EOF(1)
' Get the replacement words from the opened file.
Input #1, fileChangeFrom, fileChangeTo
EmotIcon = EmotImage(fileChangeTo, "Small")
' Replace all instances of the word to be replaced.
Selection.Find.Execute Findtext:=fileChangeFrom, ReplaceWith:=EmotIcon, MatchWholeWord:=True, Replace:=wdReplaceAll
Loop
Close #1
End Sub
The delimited list looks something like this:
"","Happy"
So, I have a sub EmotImage(strName, strSize) which inserts the correct image on the page.
here's the code for that:
Code:
Sub EmotImage(strImage As String, strSize As String)
' Insert the correct image
Set oPicture = _
Selection.InlineShapes.AddPicture _
(FileName:="\\Server\IT Files\Macros\Emoticons\Images\" & strSize & "\" & strImage & ".png", _
LinkToFile:=False, SaveWithDocument:=True)
' Now set the emoticon's size
If strSize = "Small" Then
oPicture.Width = 12
oPicture.Height = 12
End If
If strSize = "Medium" Then
oPicture.Width = 18
oPicture.Height = 18
End If
If strSize = "Large" Then
oPicture.Width = 24
oPicture.Height = 24
End If
End Sub
So, looking at all that crap that I'm probably doing totally wrong...can someone help me out?
Thanks!!!
Matt