Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Go Back  Xtreme Visual Basic Talk > > > > Inserting and modifying textboxes in Word via VBA


Reply
 
Thread Tools Display Modes
  #1  
Old 12-31-2014, 04:52 PM
jmes7827 jmes7827 is offline
Newcomer
 
Join Date: Dec 2014
Posts: 1
Question Inserting and modifying textboxes in Word via VBA


To All ...

Here is what I am trying to do. I am trying to automate the creation of "Cards Against Humanity" labels. I have a text file with a bunch of "Questions" and "Answers." The goal is that my VB6 program will read the file and then generate a word document with each line in the file in a separate text box. It currently will create the textboxes in the proper locations (I will add page breaks later). I have the bulk of the program working except I cant get access to the text boxes. Here is the code so far:

[A BUNCH OF THE NECESSARY DECLARATIONS]


Set oWordDoc = oWordApp.Documents.Add

oWordDoc.PageSetup.LeftMargin = InchesToPoints(0.5)
oWordDoc.PageSetup.RightMargin = InchesToPoints(0.5)
oWordDoc.PageSetup.TopMargin = InchesToPoints(0.5)
oWordDoc.PageSetup.BottomMargin = InchesToPoints(0.5)



' the following are loosely coded until I am sure they are accurate ...

iOrientation = msoTextOrientationHorizontal

iLeft_Base = InchesToPoints(5# / 8#)
iTop_Base = InchesToPoints(0.5)
iWidth_Base = InchesToPoints(1# + 7# / 8#)
iHeight_Base = InchesToPoints(3#)

iLeft_Add = InchesToPoints(2# + 5# / 8#)
iTop_Add = InchesToPoints(3.5)

iLeft = iLeft_Base
iTop = iTop_Base
iWidth = iWidth_Base
iHeight = iHeight_Base

iLeft_Add = InchesToPoints(2# + 5# / 8#)
iTop_Add = InchesToPoints(3.5)




For I = 1 To 3 ' iInputRecords = Number of entries in the QA file ...

' The following line CREATES each of the 3 (Hardcoded above) text boxes, but after that, I have absolutely NO way to access them ... I want to set their margins, border lines, and text given specific fonts .. Other than the text and location, each box will be identical

With oWordDoc.Shapes.AddTextbox(iOrientation, iLeft, iTop, iWidth, iHeight)


' Inserts into the document, but not the text box ... I have tried MULTIPLE ways of accessing each textbox with NO success - this is the code that is simply left over ...

Set oWordSlct = oWordDoc.ActiveWindow.Selection

oWordSlct.Font.Name = "Arial"
oWordSlct.Font.Size = 14
oWordSlct.Text = "HELLO"

' the following code loops correctly and places the textboxes correctly

If Int(I / 3) * 3 = I Then ' hit 3

iTop = iTop + iTop_Add

iLeft = iLeft_Base

Else

iLeft = iLeft + iLeft_Add

End If

End With

Next I

' More boilerplate stuff ...

Any help would be GREATLY appreciated ...
Reply With Quote
  #2  
Old 06-16-2017, 09:52 AM
Daigon Ali Daigon Ali is offline
Regular
 
Join Date: Aug 2014
Location: London
Posts: 59
Default

Assign the textbox to a variable declared as a shape.
Then use
Code:
With shp.TextFrame.TextRange
   .Font.Name = "Arial"
   .Font.Size = 14
   .Text = "HELLO"
End With
After 2.5 years, you've probably already figured that out.
Reply With Quote
Reply

Tags
font control, textboxes, vba, visual basic 6


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
 
Inserting and modifying textboxes in Word via VBA
Inserting and modifying textboxes in Word via VBA
 
-->