Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2015, 06:07 AM
kyeung kyeung is offline ActiveX Textbox properties using VBA Windows 7 32bit ActiveX Textbox properties using VBA Office 2007
Novice
ActiveX Textbox properties using VBA
 
Join Date: Oct 2015
Posts: 2
kyeung is on a distinguished road
Default ActiveX Textbox properties using VBA

Hi all,

So basically I have created a command button in the word document and I want it to create a new ActiveX Textboxes everytime I press it. I want it to preset to a certain Height and Width and with MultiLine and Vertical Scrollbar Enabled. Since I am not very familiar to VBA so I used the Record Macro option in the Developer tab. Here is the code:

************************************************** ***********
Sub ButtonForSoftwareOutputs()
'
' ButtonForSoftwareOutputs Macro
'
'
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.InlineShapes.AddOLEControl ClassType:="Forms.TextBox.1"
ActiveDocument.ViewPropertyBrowser
ActiveDocument.ViewPropertyBrowser
ActiveDocument.ViewPropertyBrowser
ActiveDocument.ViewPropertyBrowser
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
End Sub

************************************************** ***********

However, an error message pop up saying that "The ViewProperrtyBrowser method or property is not available because the current selection is an active control".



How should I write the code so that it can change the property of the ActiveX textbox? Thanks!
Reply With Quote
  #2  
Old 10-02-2015, 09:27 PM
gmayor's Avatar
gmayor gmayor is offline ActiveX Textbox properties using VBA Windows 7 64bit ActiveX Textbox properties using VBA Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Maybe something like

Code:
Dim orng As Range
Dim octrl As Object
    Set orng = ActiveDocument.Range
    orng.Collapse 0
    Set octrl = orng.InlineShapes.AddOLEControl(ClassType:="Forms.TextBox.1")
    octrl.Height = InchesToPoints(0.25)
    octrl.Width = InchesToPoints(3)
    orng.InsertParagraphAfter
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 10-03-2015, 04:40 AM
gmaxey gmaxey is offline ActiveX Textbox properties using VBA Windows 7 32bit ActiveX Textbox properties using VBA Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You will need to take Graham's suggestion a bit further to set all of the properties you are after:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oCtrl As InlineShape
  With Selection
    .MoveRight Unit:=wdCharacter, Count:=2
    Set oCtrl = .InlineShapes.AddOLEControl(ClassType:="Forms.TextBox.1", Range:=.Range)
    .MoveLeft Unit:=wdCharacter, Count:=1
    .TypeParagraph
  End With
  With oCtrl.OLEFormat.Object
    .Height = 18
    .Width = 200
    .MultiLine = True
    .ScrollBars = 2
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 10-03-2015, 04:55 AM
gmayor's Avatar
gmayor gmayor is offline ActiveX Textbox properties using VBA Windows 7 64bit ActiveX Textbox properties using VBA Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Quote:
Originally Posted by gmaxey View Post
You will need to take Graham's suggestion a bit
I was relying on your old maxim about teaching someone to fish.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 10-03-2015, 05:09 AM
gmaxey gmaxey is offline ActiveX Textbox properties using VBA Windows 7 32bit ActiveX Textbox properties using VBA Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

I don't use ActiveX controls in documents myself so in this case I had to do a lot of fishing. Looks easy served on the platter, but I broke several lines and hit several snags before landing the guppy ;-)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 10-05-2015, 12:47 AM
kyeung kyeung is offline ActiveX Textbox properties using VBA Windows 7 32bit ActiveX Textbox properties using VBA Office 2007
Novice
ActiveX Textbox properties using VBA
 
Join Date: Oct 2015
Posts: 2
kyeung is on a distinguished road
Default

Thanks!! You guys are genius!
Reply With Quote
Reply

Tags
activex, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add custom doc properties in "Doc properties control" eazysnatch Word 2 09-13-2017 08:08 PM
ActiveX Textbox properties using VBA Updating Document Properties without using advanced properties dialogue thedr9wningman Word VBA 3 01-20-2014 05:56 PM
ActiveX Textbox properties using VBA Display result in textbox based on the input of another textbox scarymovie Word VBA 5 05-16-2012 07:05 PM
How to insert a hyperlink in activex textbox Joe Patrick Word VBA 1 10-03-2011 06:03 AM
ActiveX Cquinn Outlook 0 02-08-2006 06:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft