Results 1 to 7 of 7

Thread: [RESOLVED] Powerpoint 2000, Insert Shape, FontSize Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    7

    Resolved [RESOLVED] Powerpoint 2000, Insert Shape, FontSize Problem

    Hello everyone:

    I am trying to programmatically generate a Powerpoint Slideshow out of Content stored in some XML format.

    Along the way, i sometimes need to add more than one TextArea to a slide, to display several kinds of text info
    (Standard Text: Times New Roman 24; Code Samples: Courier New 18)

    Adding another TextArea works just fine
    Code:
     MyPresentation.Slides.Item(i).Shapes.AddTextBox(....)
    but now comes the catch:

    i'm trying to apply Font Settings to this new Shape (FontName, FontSize, FontColor), and it does accept the FontName just fine, so does the FontColor.

    But it does _not_ accept the FontSize.

    Im doin it like this:
    Code:
    ' MyPresentaton as Powerpoint.Presentation
    ' ppNewShape as Powerpoint.Shape
    MyPresentation.Slides.Item(iCurSlide).Shapes.AddTextBox(Office.MsoTextOrientation.msoTextOrientationHorizontal, iLeft, iTop, iWidth, iHeight)
    ppNewShape = CType(MyPresentation.Slides.Item(iCurSlides).Shapes(MyPresentation.Slides.Items(iCurSlide).Shapes.Count - 1), PowerPoint.Shape)
    
    ppNewShape.TextFrame.TextRange.Font.Name = sNewFontName ' Works fine
    ppNewShape.TextFrame.TextRange.Font.Size = CSng(iNewFontSize) ' Doesn't Work
    ppNewShape.TextFrame.TextRange.Font.Color.RGB = RGB(iRed, iGreen, iBlue) ' Works fine

    But the FontSize of the NewShape stays the same. I've watched it with the debugger, it just doesnt accept the value. FontName works (it goes into the properties "Name" and "NameAscii" automatically, interesting), so does FontColor, but not the FontSize, and this is drivin me crazy.

    Due to the environment i have to work in i'm limited to Office2000, but i do have Visual Studio 2008....

    Could this be a Powerpoint Bug, could the Property Getter for "Font.Size" be wrong (like in the guessing game a few days ago in the VB Wire News)?

    Does anyone know how i could get this to work? Any help is appreciated,
    Solutions, Workarounds, i'll take anything... *desparate*

    Thanx in advance...

    Mike aka StoneTheIceman

    =============================

    Supplement:

    I've got the code i use by recording a VBA-Macro inside Powerpoint and cut'n'pasting
    the code into my Studio Project.... inside Powerpoint VBA it works just fine (including FontSize!!!),
    but the very same code ran by Visual Studio against Powerpoint - nada.
    I'm helpless........
    Last edited by StoneTheIceman; Sep 11th, 2009 at 09:46 AM.

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Powerpoint 2000, Insert Shape, FontSize Problem

    Insert this line

    Msgbox CSng(iNewFontSize)

    before

    ppNewShape.TextFrame.TextRange.Font.Size = CSng(iNewFontSize)

    and then tell me what do you get?

    Also Hardcode the line and check if it works... for example

    ppNewShape.TextFrame.TextRange.Font.Size = 14
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    7

    Re: Powerpoint 2000, Insert Shape, FontSize Problem

    thx for the reply, koolsid, i'll try that in a minute...

    just now i realized something, dont know why i didnt notice that before:

    the Powerpoint-VBA-Macro accesses the shape via
    Code:
    ActiveWindow.Selection.TextRange.Font.Size=18
    where i did it by
    Code:
    MyPresentation.Slides.Item(iCurSlide).Shapes(iShapeID).TextFrame.TextRange.Font.Size
    i'm gonna check if that might make the difference...

    Be back when i got news...

    Mike

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    7

    Resolved Re: Powerpoint 2000, Insert Shape, FontSize Problem

    OK, i solved it... at least THIS one...

    When i accessed the Shape via
    Code:
    MyPresentation.Slides.Item(iCurSlide).Shapes(iCurShape).Select()
    ActiveWindow.Selection.TextRange.Font.Size=18
    as the recorded VBA-Macro does, it works just fine.
    Why my previous attempt,
    Code:
    MyPresentation.Slides.Item(iCurSlide).Shapes(iShapeID).TextFrame.TextRange.Font.Size
    didn't work, i still don't know.

    But now i hit another bump:

    The stuff i'm writing in these shapes sometimes contains HTML/CSS/XML code. For better readability, i want to write the various elements of that source code in different colors (Tags, Attributes, Values, Selectors, KeyWords,...), like dreamweaver or other webeditors do.

    to achieve that, i need to select the word i just added to the PowerPoint-Shape, and change its font properties (thats where my above situation came from).

    Now, the changing font properties itself works now but i hit a new one:

    The only way i know to select a certain word out of a PowerPoint-Shape, is to measure the Shape's Content's length before adding the new word, measure the length again after adding the new word, and do this:
    Code:
    ' ppShape as PowerPoint.Shape
    ppShape.TextFrame.TextRange.Characters(iLengthBefore, iLengthAfter-iLengthBefore).Select()
    in Theory, the word i just entered should be selected, like it would be selected if i did it manually by mouse, correct?

    Wrong!

    The more text the PowerPoint-Shape already contains before my desired word, the more off the selection i get by Characters(..).Select() is.

    Assume, my PowerPoint Shape contains a total of 8 lines of text.
    In the first 2 lines all my selections and font-changes seemingly work well.
    In the 3rd line, every selection i make with the character-positions i calculated by the above method, are one character off, they start one character right of where supposed to, and ends one char right of where supposed to.
    In Line 4, every selection is shifted 2 chars to the right, in Line 5 its 3 chars off, and so on.

    Guessing Game: Who knows why this is the case? and who wants to know the solution? PM or Mail me! ;-)

    for the record... it took me 3 hours to figure out WHY it did that, another hour to accept the fact theres nothing i can do about it, and 10 mins to code a workaround.... a workaround for a dumb problem that in a better world shouldnt exist at all, but oh well.... this is microsoft's world... :shrug:

    See ya,

    Mike aka Stone the Iceman

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    7

    Re: [RESOLVED] Powerpoint 2000, Insert Shape, FontSize Problem

    BTW koolsid,

    your suggestions - im sorry - didnt solve my problem. as long as i acecssed the Shape via MyPresentation.Slides(..).Shapes(..), it wouldnt work.

    Only switching to ActiveWindow.Selection (after selecting the Shape) brought the solution.....

    Why?

    hell if i know....

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Powerpoint 2000, Insert Shape, FontSize Problem

    Guessing Game: Who knows why this is the case? and who wants to know the solution? PM or Mail me! ;-)
    Would suggest you to post the reason. I am saying this because what if someone has the same problem 2yrs down the line? Would it be practical for the member to pm you every time
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    7

    Re: [RESOLVED] Powerpoint 2000, Insert Shape, FontSize Problem

    Good Point koolsid... havent thought that far ahead....

    Alright, the reason for the odd-looking results when adding a list of strings to a PowerpointShape and formatting them afterwards one by one is this:

    When you add a one-byte-LineBreak (Hex13) to the content of the PowerPointShape, the ContentString actually becomes 2 bytes longer.
    (as measured with the Len()-Function, before and after adding the new line)

    When you add a two-byte-LineBreak (vbCrLf, or Hex10+Hex13) to the content of the PowerPoint-Shape, the Content-String actually becomes 3 bytes longer.

    Dont ask me why it does that, i only know it does, but that throws all the content-length-measurements off balance...

    What i had to do to get it work, is take the "Begin" StringIndex i measured before adding the line to the content, and substract from it the number of Hex13's in the string up to that Position...

    Say, i want to format the 4th line of the shape, and before i added the text of this line, the content so far was, say, 72 bytes long, the actual begin
    of the characters of the 4th line is ByteNo 69 of the ShapeContentString.

    An added reason i think for this "wrong measured" String-Positions is the method by which one has to select the content in order to format it:
    Code:
    ' ppShape as PowerPoint.Shape
    ppShape.TextFrame.TextRange.Characters(iLengthBefore, iLengthAfter-iLengthBefore).Select()
    Note the PropertyName: "Characters"... other Properties of the TextRange-Object are Lines, Words, Runs....

    I think that "Characters" does not contain all of what i consider characters of a string, but only letters, figures, but ignores chars like Hex13....

    So, if in the future anyone has a prob like that, maybe that helps....

    See 'ya 'round...

    Mike aka Stone the Iceman


    Oh: one more thing i encountered:
    When a PowerPointShape contains, say, 10 lines of text, initially they all have the PowerPointDefaultFontSize of, say, 28 (depending on the DesignTemplate applied to the presentation).

    When i went to formatting the lines one by one, among other things reducing their FontSize to 20 i noticed something:

    At some point during the resizing, i had like 7 lines of them 10 formatted to FontSize20, Powerpoint suddenly resized the first 6 Lines to FontSize 24, all by itself.

    I found out that in the "AutoForm Properties" of this Shape there is a CheckBox hidden "Fit Shapes Size to Text" that has to be checked (by default its not), or PowerPoint does it the other way round: automatically fit (means: resize) the text to the shape...
    (I'm on another machine right now, i'll add the VBA-Code for this later, sorry)

    All in all, Powerpoint's myriad of un-turnoffable automatics are a pain, but when working for a training and education company, i have to bear with it...
    Last edited by StoneTheIceman; Sep 15th, 2009 at 12:41 PM. Reason: duh, check grammar when rewriting a sentence 5 times...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width