Results 1 to 8 of 8

Thread: [resolved] changing a controls propertry - WORD

  1. #1

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Resolved [resolved] changing a controls propertry - WORD

    Hi all,

    I have such a problem:

    How can I change a controls properties, while referring to the control's name
    using a variable??? I have 50 labels named: label1, label2, label3,...,label50. And I would like programmatically change properties of all this labels using loop???
    Controls are embedded in document NOT in the form.
    I am using Word 2003.

    Please help.

    Regards,
    sweet_dreams
    Last edited by sweet_dreams; Mar 4th, 2006 at 04:11 PM.

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

    Re: changing a controls propertry - WORD

    This will work for the ActiveX controls.
    VB Code:
    1. ThisDocument.TextBox1.Text = "Test"
    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

  3. #3

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: changing a controls propertry - WORD

    Thx RobDog888

    But what should I do to be able to change for examlple 100 such a controls. I would like to use loop to change it's properties at the same time. So how can refer to controls property for eg.
    VB Code:
    1. for i=1 to 100
    2. text&i.text="hello" & I
    3. next i
    I know that above code looks ridiculous but I would like to do sth like that.
    Please help,
    sweet_dreams

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

    Re: changing a controls propertry - WORD

    ]For Each ctl in ThisDocument.InlinShapes
    VB Code:
    1. Dim ctl As InlineShape
    2. For Each ctl In ThisDocument.InlineShapes
    3.     ctl.OLEFormat.Object.Text = "Test"
    4. Next
    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
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: changing a controls propertry - WORD

    VB Code:
    1. Dim i as integer
    2. For i = 1 to Thisdocument.inlineshapes.count
    3.     ThisDocument.InlineShapes(i).OLEFormat.Object.Text = "Test " & i
    4. Next
    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

  6. #6

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: changing a controls propertry - WORD

    Thx once again RobDog888, it works fine.

    But do you know is it possible to change properties of only particular control for eg. Label ??? Because I have not only labels but also other controls.

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

    Re: changing a controls propertry - WORD

    Yes, you would have to "filter" out to just the type of control you want to edit or by its control name.
    VB Code:
    1. ThisDocument.InlineShapes(i).Type =wdInlineShapeOLEControlObject
    2.  
    3. ThisDocument.InlineShapes(i).OLEFormat.Object.Name
    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

  8. #8

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: changing a controls propertry - WORD

    Thx RobDog888

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