The VBA works great but here is my purpose, perhaps you can help:
It is my goal to allow a user to, with one button, insert their signature (image file with their written name). To make this look good no matter the document I needed to insert a simple text box with no line (outline) and no fill. Then insert a .png image file into the text box (from a network drive //server name/user/signatures/username.png).
This will allow the user to position the textbox whereever they want but ideally with your VBA above it should be whereever the mouse was when they hit the shortcut...
Can a macro do this? I cant seem to get the textbox formatted with no line and no fill, once this issue is resolved, it doesn?t seem to be able to insert a file into the textbox. Any assistance would be greatly appreciated. Let me know if I'm too far off base and I'll start a new thread...
Greg Maxey wrote:
Geoff,The one thing you version is missing (to replicate exactly the " simple
05-Mar-10
Geoff
The one thing you version is missing (to replicate exactly the " simple tex
box" building block) is the ContentControl. In the building bloc there is
content control inside the textbox and the text is inside the conten
control. If it matters
Sub ScratchMaco(
Dim oShape As Shap
Dim CurrentCursorVerticalPosition As Doubl
Dim PosLeftMargin As Doubl
Dim oCC As ContentContro
' Get position of left margin relative to left edge of pag
PosLeftMargin = ActiveDocument.PageSetup.LeftMargi
' Get vertical position of curso
CurrentCursorVerticalPosition
Selection.Information(wdVerticalPositionRelativeToPage
' Insert text box at centre of current lin
Set oShape = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal
PosLeftMargin + 136, CurrentCursorVerticalPosition, 180, 100
With oShape.TextFram
..AutoSize =
Set oCC = .TextRange.ContentControls.Ad
oCC.PlaceholderText = "[Type a quote from the document or the summary o
an "
& "interesting point. You can position the text box anywhere in th
document."
& " Use the Text Box Tools tab to change the formatting of the pul
quote text box.]
..TextRange.Selec
End Wit
End Su
Geoff Budd wrote:
Previous Posts In This Thread:
Macro to insert a text box in Word 2007
Does anyone know how I can insert a particular type of text box ("Simple Tex
Box")into a Word 2007 document using a macro (so that I can add it as
button to the Quick Access Toolbar)
it is easy enough to add a button to the Quick Access Toolbar to open up th
Text Box Gallery (by using one of the pre-defined customise commands), but
just want to be able to open the "Simple Text Box" with one click, rathe
than having to select it from the Text Box Gallery every time
Many thanks.
If you mean "Simple Text Box" as defined by the Building Blocks.
If you mean "Simple Text Box" as defined by the Building Blocks.dot
template then
Sub Macro1(
Dim oTmp As Templat
Dim bExists As Boolea
bExists = Fals
Templates.LoadBuildingBlock
For Each oTmp In Template
If oTmp.Name = "Building Blocks.dotx" The
oTmp.BuildingBlockEntries(" Simple Text Box").
Insert Where:=Selection.Range, RichText:=Tru
bExists = Tru
Exit Fo
End I
Nex
If Not bExists Then MsgBox "The building block was not found
End Su
If you just a truly simple square textbox then something like this
Sub Macro2(
ActiveDocument.Shapes.AddTextbox msoTextOrientationHorizontal, 5, 5, 100
10
End Su
Geoff Budd wrote:
Hi Greg,Thanks for this - excellent!
Hi Greg
Thanks for this - excellent! Yes, I did mean "Simple Text Box" as define
by Building Blocks.dotx
Just one more thing ... I am just trying to reduce the total number of mous
clicks to one - i.e. clicking the macro button to insert the text box an
then being able to start typing the text straight away. So, is there any wa
I can leave the focus inside the text box, so that I can start typing tex
straight away without having to click inside the box first (rather like when
you insert a text box from the gallery)?.
Many thanks.
:
Try:Sub ScratchMaco()Dim oShape As ShapeSet oShape = ActiveDocument.Shapes.
Try:
Sub ScratchMaco()
Dim oShape As Shape
Set oShape = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,
200, 200, 200, 100)
oShape.TextFrame.TextRange.Text = "[Type a quote from the document or the
summary of an " _
& "interesting point. You can position the text box anywhere in the
document." _
& " Use the Text Box Tools tab to change the formatting of the pull
quote text box.]"
oShape.TextFrame.TextRange.Select
End Sub
Hi Greg - nearly there!
Hi Greg - nearly there!
I just need to make sure the text box is inserted at (or on the same line
as) the cursor (i.e. current selection); and
have the text box automatically resize itself depending on how much text is
typed in (as the "Simple Text Box" does).
Sorry to be pernickity but I am sure we have nearly cracked it!
Regards.
:
We've nearly cracked it!!
We've nearly cracked it!! Seems that I am doing the cracking while you are
moving the goal posts after the start of the game ;-)
Try:
Sub Insert_TB_at_Selection()
Dim oShape As Shape
Dim i As Long
i = Selection.Information(wdVerticalPositionRelativeToPage)
Set oShape = ActiveDocument.Shapes.AddTextbox _
(msoTextOrientationHorizontal, 200, i, 150, 20)
With oShape.TextFrame
..AutoSize = 1
..TextRange.ContentControls.Add
..TextRange.Select
End With
End Sub
Hi Greg,I have solved the problem - see below
Thanks so much for your help -
Hi Greg,
I have solved the problem - see below:
(Thanks so much for your help - you are a star!)
Sub InsertTextBox()
'
' Inserts a Text Box at the centre of the line where the keyboard cursor is.
'
Dim oShape As Shape, CurrentCursorVerticalPosition As Variant
Dim PosTopMargin As Variant
' Get position of left margin relative to left edge of page
PosLeftMargin = ActiveDocument.PageSetup.LeftMargin
' Get vertical position of cursor
CurrentCursorVerticalPosition =
Selection.Information(wdVerticalPositionRelativeToPage)
' Insert text box at centre of current line
Set oShape = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,
PosLeftMargin + 136, CurrentCursorVerticalPosition, 180, 100)
oShape.TextFrame.TextRange.Text = "[Type a quote from the document or the
summary of an " _
& "interesting point. You can position the text box anywhere in the
document." _
& " Use the Text Box Tools tab to change the formatting of the pull
quote text box.]"
' Set text box property: "Resize AutoShape to fit text"
oShape.TextFrame.AutoSize = True
oShape.TextFrame.TextRange.Select
End Sub
:
Thanks for this, Greg - that does exactly what I need.
Thanks for this, Greg - that does exactly what I need.
I did not mean to imply that anyone other than you had cracked the problem,
and I should have made it clearer at the beginning what I was after - that
is, to be able to use a single click to insert a simple text box (including
correct placing of the text box on the page, having it autosize, and
retaining the focus) - i.e. to replicate exactly what "Insert, Text Box,
Simple Text Box" does.
Many thanks again for your patience and expertise.
Regards,
Geoff
:
Geoff,No harm, no foul. I was just giving you a little friendly ribbing.
Geoff,
No harm, no foul. I was just giving you a little friendly ribbing. I saw
your version and glad you have what you need.
Geoff,The one thing you version is missing (to replicate exactly the " simple
Geoff,
The one thing you version is missing (to replicate exactly the " simple text
box" building block) is the ContentControl. In the building bloc there is a
content control inside the textbox and the text is inside the content
control. If it matters:
Sub ScratchMaco()
Dim oShape As Shape
Dim CurrentCursorVerticalPosition As Double
Dim PosLeftMargin As Double
Dim oCC As ContentControl
' Get position of left margin relative to left edge of page
PosLeftMargin = ActiveDocument.PageSetup.LeftMargin
' Get vertical position of cursor
CurrentCursorVerticalPosition =
Selection.Information(wdVerticalPositionRelativeToPage)
' Insert text box at centre of current line
Set oShape = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,
_
PosLeftMargin + 136, CurrentCursorVerticalPosition, 180, 100)
With oShape.TextFrame
..AutoSize = 1
Set oCC = .TextRange.ContentControls.Add
oCC.PlaceholderText = "[Type a quote from the document or the summary of
an " _
& "interesting point. You can position the text box anywhere in the
document." _
& " Use the Text Box Tools tab to change the formatting of the pull
quote text box.]"
..TextRange.Select
End With
End Sub
Geoff Budd wrote:
This may belong in a new post but if I could ask two more tasks or functionality?
The VBA works great but here is my purpose, perhaps you can help:
It is my goal to allow a user to, with one button, insert their signature (image file of their written name). To make this look good no matter the document I needed to insert a simple text box with no line (outline) and no fill. Then insert a .png image file into the text box (from a network drive //server name/user/signatures/username.png).
Can a macro do this? I cant seem to get the textbox formatted with: no line and no fill, once this issue is resolved, it doesn?t seem to be able to insert a file into the textbox from a network share. Any assistance would be greatly appreciated. Let me know if I'm too far off base and I'll start a new thread.
Submitted via EggHeadCafe - Software Developer Portal of Choice
ASP.NET Providerless Custom Forms Authentication, Roles and Profile with MongoDb
http://www.eggheadcafe.com/tutorial...ntication-roles-and-profile-with-mongodb.aspx