PDA

View Full Version : Working with Textboxes or variant



JohnnyBravo
06-29-2006, 10:32 AM
In a Word doc with several textboxes, all i want to do is select the first textbox and bold just the first line within the box (as well as make the font bigger). The code below is ineffective as it bolds the entire box rather than just the first line. What change do i need to make?


Sub Select1stline()
'
' Select1stline Macro
' Macro recorded 6/29/2006 by John


With Selection.Frames(1)
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Font.Size = 14
End With
End Sub

Killian
06-29-2006, 11:44 AM
Sometimes, looking at a recorded macro just confuses the issue. Never more so than in Word working with the selection object, which is replicating user interaction with the document.
This is a case in point.

Sub Select1stline_v2()
'
' Select1stline Macro
' Macro recorded 6/29/2006 by John
' Macro edited 6/29/2006 by Killian :-)
' Just run on any document

'make sure there are some frames
If ThisDocument.Frames.Count > 0 Then
'navigate through the object model to the font of
' the first paragraph of the first frame in the document
With ThisDocument.Frames(1).Range.Paragraphs(1).Range.Font
' do stuff to the font
.Bold = wdToggle
.Size = 14
End With
End If

End Sub

Killian
06-29-2006, 12:04 PM
Unless you really mean the first line, rather than the paragraph...
Then I suppose a brief interaction with the selection is in order:Sub Select1stline_v3()

If ThisDocument.Frames.Count > 0 Then
' navigate through the object model to the font of
' the first paragraph of the first frame in the document
' and select it
ThisDocument.Frames(1).Range.Paragraphs(1).Range.Select
With Selection
' modify the selection to the first line
.Collapse (wdCollapseStart)
.MoveEnd Unit:=wdLine, Count:=1
' do stuff to the font
.Font.Bold = wdToggle
.Font.Size = 14
End With
End If

End SubBut then, how do you know making the 1st line bold and 14pt won't make it wrap to the 2nd line?

JohnnyBravo
06-29-2006, 02:41 PM
But then, how do you know making the 1st line bold and 14pt won't make it wrap to the 2nd line?

hehe... good point. :)


Your code above for some reason is not working for me - and my hunch is that the reason is perhaps that these are not truly text boxes that I'm dealing with. (And that's why I put in the subject line "...or variant").

What's going on is that I've scanned a bunch of resumes and consequently converted into RTF using an OCR software. So perhaps something funky is going on during the conversion process.

I will upload a sample for you so you can see for yourself what these are.

Thanks for recoding that macro for me BTW.

lucas
06-29-2006, 07:24 PM
Hey Johnny just open the rtf in word and do a file-save as and select doc type .doc then insert the module and run the macro from post 3. It made the first line in the first textbox bold for me and enlarged the font.

JohnnyBravo
06-30-2006, 07:09 AM
Unfortunately these documents have to remain in RTF format. The reason is because once the documents are "cleaned" up - we use a vendor/software where we upload it into their database. Their software parses the resume and it has be to be in a RTF format for it to work. I appreciate all your help here nevertheless.

lucas
06-30-2006, 07:13 AM
convert it-run the macro-convert it back...

JohnnyBravo
06-30-2006, 10:34 AM
convert it-run the macro-convert it back...

OK, I saved it as a DOC and when I ran Killians code - nothing happened. Odd. I tried both of his suggestions above and notta. :dunno

lucas
06-30-2006, 11:05 AM
You must not have saved it as a word document because it works for me.

Open the file in Word. Then go to file and click on save as
Drop the "Save as Type" box and look for "Word Document(*.doc)
Then save it and put your macro in a module and run it.

Attached example:
The point is that this can all be automated once you see it work.

JohnnyBravo
06-30-2006, 11:12 AM
Seriously, that is exactly what I did (File > Save As...) and I'm tellin ya - no workie. :(

EDIT:

I just tried it on my home PC and it worked fine. That is rather odd. Both my home and work PC have Office 2003 loaded so I don't know what is going on.

JohnnyBravo
06-30-2006, 06:16 PM
While we're on the subject does VBA treat text boxes versus frames differently?

The reason why I ask is that when I double click on the frame in the RTF, i get the first menu. In contrast when I create a textbox in a Word *.doc, I get the 2nd menu.


http://i5.photobucket.com/albums/y182/tushman/ScreenHunter_009.jpg



http://i5.photobucket.com/albums/y182/tushman/ScreenHunter_011.jpg

fumei
06-30-2006, 07:37 PM
Yup.