PDA

View Full Version : Increase font size by 1pt and Page Break



JohnnyBravo
07-07-2006, 01:33 PM
I've been told the Range is much better to use in VBA coding (rather than the "Selection" method). So I tried to scrounge up some examples on Google but being a VBA newbie, I have been unsuccessful so far. My botched example below is not working. I probably have the wrong syntax on creating the page break as desired. What do I need to change. Also can anyone help w/ the font issue? Thanks in advance.

Sub Increase_FontSize()
'
' Increase_FontSize Macro
' Macro recorded 7/7/2006 by John
'
ActiveDocument.PageSetup.TopMargin = InchesToPoints(0.8)
ActiveDocument.PageSetup.LeftMargin = InchesToPoints(0.81)
ActiveDocument.PageSetup.RightMargin = InchesToPoints(0.71)
ActiveDocument.Frames.Delete
Selection.WholeStory
With Selection.Font
.Grow
' I need VBA to detect whatever the current font size is and
' increase it by 1 pt
End With
ActiveDocument.Range.EndOf (wdWholeStory)
.InsertBreak Type:=wdPageBreak
Selection.TypeParagraph
Selection.TypeParagraph
End Sub

fumei
07-08-2006, 12:15 AM
Please, when you have something "not working", we need to know what it IS doing.
I have been unsuccessful so far. My botched example below is not working.
Selection.WholeStory
With Selection.Font
.Grow
' I need VBA to detect whatever the current font size is and
' increase it by 1 pt
End With OK, you have selected the entire document. If there is even ONE font size change, you will NOT be able to detect the font size. You can easily find out the selection font size;MsgBox Selection.Font.Sizebut if there is any changes of font size within the selection it comes back as 999999 - or..."how the heck do I know? WHICH ONE????"

So. You select the entire document. Is the ENTIRE document one font size? If so, then you can progress with this.

Note that .Grow does NOT increase the font size by 1 pt. It increases it to the next available (STANDARD!!!!!) pt size. That is...if the font size = 22, then .Grow will make the font size 24...NOT 23.Selection.Font.Size = Selection.Font.Size + 1will increase the selection.font size by 1 point.

If you just want to go to the end of the document and add a page, thenWith Selection
.EndKey Unit:=wdStory
.InsertBreak Type:=wdPageBreak
End WithLastly, what is with ActiveDocument.Frames.Delete what is happening here???

fumei
07-08-2006, 12:17 AM
And yes, generally speaking, it IS better to work with Range, rather than Selection. If I could figure out what you are trying to do I could probably suggest something.

JohnnyBravo
07-10-2006, 11:03 AM
And yes, generally speaking, it IS better to work with Range, rather than Selection. If I could figure out what you are trying to do I could probably suggest something.

I purposely left out the background story because I didn't think it was really pertinent to this specific post. Anyway, to provide you with the full picture, here it is.

I'm scanning several resumes via a flatbed scanner. The OCR software converts it to a RTF document and then afterwards, I end up making several edits to the document in Word. When they are finished editing, I have to upload each one into our resume database via an extranet. When I upload it, the software parses the resume; based on the content of the resume, it automatically fills in certain fields on the website like Education, Work Experience, etc. If you would like to see for yourself what these coverted resumes look like, I've uploaded a sample in this (http://vbaexpress.com/forum/showthread.php?t=8621) previous thread.

You asked me what's going on w/ the "ActiveDocument.Frames.Delete" line in my coding. I put that in there because when the scanner software converts it to a RTF document, it uses several text frames (not boxes) throughout the resume. That's a problem because when I upload it onto our extranet, it doesn't always know that the work experience portion has been split up into several text boxes and a person might show as having only 1 job experience. Therefore, I have found it's best to remove ALL text frames from the document. This isn't really pertinent to some of the other problems I'm having.

I asked about the font issue because the OCR software is pretty decent, but it's not perfect. Sometimes it will shrink down the font size compared to the original document. And in some cases it will use different font and different font sizes througout a single resume.

Again - these are all annoyances that I wish I knew better to handle via VBA but I'm such a newbie I only know how to address a couple of simple issues. For instance, I ended up using the macro recorder (in Word) to get an idea how to do certain things such as deleting the text frames, activating the next window etc. But beyond that I'm don't know how to do more complex tasks.

I'm trying to minimize the work that you guys have to do here; that's why I'm trying to put some effort forth in creating my own macros (or codes) before coming to the forums for help. If my posts seem a bit disjointed or confusing to you, I apologize for I'm not always thinking in a linear fashion.

fumei
07-10-2006, 10:46 PM
I asked about the font issue because the OCR software is pretty decent, but it's not perfect. Really????

:rotflmao:

Ok...enough fun. Thanks for the explanation. Don't worry about overburdening us...hey, we don't so this for money. if we don't feel like doing it...we won't.

So...where we you with this? Do you have answers for it? RE: font size change As stated, if there are any font size changes within the range of a selection, you can not get information on font size. However, if what you want is a GLOBAL font size change (ie. just change everything up one Point) then the code line above will do.

What else (specifically) can we help with?

Is your page break working the way you want?

JohnnyBravo
07-11-2006, 08:06 AM
So...where we you with this? Do you have answers for it? RE: font size change
That's the thing I was unaware of. There are indeed different font sizes throughout the document. But somtimes the scanner does a great job and the font sizes are consistent throughout. I thought that the VBA code would just default to the largest or the smallest font size found in the document.

In another words, if 10 pt & 11 pt are used in the same document, I thought VBA would round up to the next largest (12 pt). The main goal was to be able to make the font grow by 1 pt. So if 12 pt was used, I wanted to grow to 13 pt. I couldn't figure out how to use the "grow" command to increase it by 1. Thanks for proper coding.



What else (specifically) can we help with?

Is your page break working the way you want?
The page break is fine. I'm working on something right now, and if I can't figure out how to do it on my own, I might come back for your expertise. Thanks for the help.