Results 1 to 7 of 7

Thread: [RESOLVED] Formatting Word Textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Resolved [RESOLVED] Formatting Word Textbox

    Hi,

    I trying to write a program in VB6 that will update word templates to remove the existing gif logo (which is part of a group of items) and replace it with a True Type Fonts version of the logo.

    So far I've been able to ungroup the items, delete the picture and create a textbox in it's place. What I need to do now is change the colour of the outline of the textbox from black to white (or clear) and then insert the text "abc" into the textbox, using font "company logo" and font size 72.

    Any ideas how I do this? My code so far is listed below.

    Cheers,

    Toashy



    Private Sub updateTemplates(strPath As String, strFileName As String)


    Dim strSaveTo As String
    Dim GroupName As String

    strSaveTo = "C:\New Templates" & "\" & strFileName


    Set oApp = New Word.Application
    Dim oDoc As Word.Document

    Set oDoc = oApp.Documents.Open(strPath)

    'Ungroup
    If oDoc.Shapes(1).Type = msoGroup Then
    oDoc.Shapes(1).Ungroup
    End If


    'Delete Picture Logo
    If oDoc.Shapes(1).Type = msoPicture Then
    oDoc.Shapes(1).Delete
    End If


    'Create TextBox
    Dim TextBox1

    Set TextBox1 = oDoc.Shapes. _
    AddTextbox(msoTextOrientationHorizontal, 31.05, _
    45.2, 63#, 81#)



    oDoc.SaveAs FileName:= _
    strSaveTo _
    , FileFormat:=wdFormatTemplate, LockComments:=False, Password:="", _
    AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
    EmbedTrueTypeFonts:=True, SaveNativePictureFormat:=False, SaveFormsData:= _
    False, SaveAsAOCELetter:=False

    oDoc.Close

    Set oApp = Nothing


    End Sub

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Formatting Word Textbox

    did u try recording a macro of it then viewing the code?

    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Re: Formatting Word Textbox

    Static, thanks for the welcome and the quick reply.

    Thanks for the advice, I didn't know you could do that, that'll save me a lot a hassle in the future.

    The code I got is:

    ActiveDocument.Shapes("Text Box 14").Select
    Selection.Font.Name = "Company logo"
    Selection.Font.Size = 72
    Selection.TypeText Text:="abc"

    This doesn't work though. For some reason I'm not able to record the action of clicking into the textbox before adding the text so this might be causing the problem.

    Any ideas?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Formatting Word Textbox

    Recording macros only will generate code for certain actions, just as mouse clicks are disabled for this type of macro recording. Try this...
    VB Code:
    1. ActiveDocument.Shapes("Text Box 14").Activate
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Re: Formatting Word Textbox

    Thanks, here's my current code for the text box.

    Dim TextBox1
    Set TextBox1 = oDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, 31.05, 45.2, 63#, 81#)
    oDoc.Shapes(5).Select
    Selection.Font.Name = "Company logo"
    Selection.Font.Size = "72"
    Selection.TypeText Text:="abc"
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoFalse


    I'm now able to update the first template as required but I hit problems when I try to itterate through the other templates as their reference to the new textbox is different, i.e. not always Shapes(5). I've tried code like:

    oDoc.Shapes(TextBox1).Select and oDoc.TextBox1.Select but this doesn't work.

    Any idea how I can set the reference when creating the Text box so it is the same on all templates?

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    4

    Re: Formatting Word Textbox

    I managed to get this sorted by changing the lines:

    Dim TextBox1
    Set TextBox1 = oDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, 31.05, 45.2, 63#, 81#)
    oDoc.Shapes(5).Select

    to

    oDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, 31.05, 45.2, 63#, 81#).Select

    Thanks for pointing me in the right direction.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Formatting Word Textbox

    Well if you have multiple templates referenced then from the other template projects you will need to reference the main project name first.

    Also, instead of the index you can pass the textbox's name.

    oDoc.Shapes("TextBox1").Select but from the other templates you will need the project name first.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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