Command Button Troubles - Word 2010

heathertank
NewLounger
Posts: 11
Joined: 28 Jul 2010, 20:35

Command Button Troubles - Word 2010

Post by heathertank »

I am trying to create a command button that when clicked will insert content into the document. The problem is that when I click the button, the content inserts successfully but also deletes the command button during the process. What is it that I'm doing wrong?

Thanks,
Heather

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command Button Troubles - Word 2010

Post by HansV »

Could you post the code behind the command button? Thanks in advance!
Best wishes,
Hans

heathertank
NewLounger
Posts: 11
Joined: 28 Jul 2010, 20:35

Re: Command Button Troubles - Word 2010

Post by heathertank »

Sure - here you go Hans...thanks!

Code: Select all

'
' InsertInfo Macro
'
'
    With Selection.Font
        .Name = "Cambria"
        .Size = 14
        .Bold = True
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = -553598977
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Spacing = 0
        .Scaling = 100
        .Position = 0
        .Kerning = 0
        .Animation = wdAnimationNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    Selection.TypeText Text:="Insert Product Name"
    Selection.TypeParagraph
    Selection.ClearFormatting
    With Selection.Font
        .Name = "Cambria"
        .Size = 12
        .Bold = False
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = wdColorAutomatic
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Spacing = 0
        .Scaling = 100
        .Position = 0
        .Kerning = 0
        .Animation = wdAnimationNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    Selection.TypeText Text:="Insert the opening paragraph about the product."
    Selection.TypeParagraph
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=6, NumColumns:= _
        2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitWindow
    With Selection.Tables(1)
        If .Style <> "Table Grid" Then
            .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
    End With
    Selection.Tables(1).Select
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 6
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Product Number:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Picture:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Description:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Price:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Quantities Available:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Volume Discounts"
    Selection.Tables(1).Select
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 6
        .SpaceBeforeAuto = False
        .SpaceAfter = 6
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Move Unit:=wdColumn, Count:=-1
    Selection.SelectColumn
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Move Unit:=wdColumn, Count:=-1
    Selection.SelectColumn
    Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
    Selection.Columns.PreferredWidth = InchesToPoints(2)
    Selection.MoveDown Unit:=wdLine, Count:=1
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 10
        .SpaceBeforeAuto = False
        .SpaceAfter = 10
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceMultiple
        .LineSpacing = LinesToPoints(1.15)
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.TypeText Text:= _
        "To order, please visit our website at http://www.northwindtraders.c"
    Selection.TypeText Text:="om."
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdWord, Count:=5, Extend:=wdExtend
    Selection.Copy
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        "http://www.northwindtraders.com/", SubAddress:="", ScreenTip:="", _
        TextToDisplay:="www.northwindtraders.com"
    Selection.MoveDown Unit:=wdLine, Count:=2
    Selection.EndKey Unit:=wdLine
    Selection.TypeParagraph
    Selection.TypeParagraph
End Sub
Last edited by HansV on 05 Aug 2011, 17:39, edited 1 time in total.
Reason: to enclose code in [code] and [/code] tags

heathertank
NewLounger
Posts: 11
Joined: 28 Jul 2010, 20:35

Re: Command Button Troubles - Word 2010

Post by heathertank »

I didn't realize the first line didn't copy ... here it is in case you need it ... sorry about that.

Code: Select all

Private Sub CommandButton1_Click()
'
' InsertInfo Macro
'
'
    With Selection.Font
        .Name = "Cambria"
        .Size = 14
        .Bold = True
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = -553598977
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Spacing = 0
        .Scaling = 100
        .Position = 0
        .Kerning = 0
        .Animation = wdAnimationNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    Selection.TypeText Text:="Insert Product Name"
    Selection.TypeParagraph
    Selection.ClearFormatting
    With Selection.Font
        .Name = "Cambria"
        .Size = 12
        .Bold = False
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = wdColorAutomatic
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Spacing = 0
        .Scaling = 100
        .Position = 0
        .Kerning = 0
        .Animation = wdAnimationNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    Selection.TypeText Text:="Insert the opening paragraph about the product."
    Selection.TypeParagraph
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=6, NumColumns:= _
        2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitWindow
    With Selection.Tables(1)
        If .Style <> "Table Grid" Then
            .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
    End With
    Selection.Tables(1).Select
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 6
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Product Number:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Picture:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Description:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Price:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Quantities Available:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Volume Discounts"
    Selection.Tables(1).Select
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 6
        .SpaceBeforeAuto = False
        .SpaceAfter = 6
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Move Unit:=wdColumn, Count:=-1
    Selection.SelectColumn
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Move Unit:=wdColumn, Count:=-1
    Selection.SelectColumn
    Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
    Selection.Columns.PreferredWidth = InchesToPoints(2)
    Selection.MoveDown Unit:=wdLine, Count:=1
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 10
        .SpaceBeforeAuto = False
        .SpaceAfter = 10
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceMultiple
        .LineSpacing = LinesToPoints(1.15)
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.TypeText Text:= _
        "To order, please visit our website at http://www.northwindtraders.c"
    Selection.TypeText Text:="om."
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdWord, Count:=5, Extend:=wdExtend
    Selection.Copy
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        "http://www.northwindtraders.com/", SubAddress:="", ScreenTip:="", _
        TextToDisplay:="www.northwindtraders.com"
    Selection.MoveDown Unit:=wdLine, Count:=2
    Selection.EndKey Unit:=wdLine
    Selection.TypeParagraph
    Selection.TypeParagraph
End Sub
Last edited by HansV on 05 Aug 2011, 17:39, edited 1 time in total.
Reason: to enclose code in [code] and [/code] tags

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command Button Troubles - Word 2010

Post by HansV »

Try inserting these lines at the beginning of the macro:

Code: Select all

    Selection.MoveDown Unit:=wdLine
    Selection.TypeParagraph
Best wishes,
Hans

heathertank
NewLounger
Posts: 11
Joined: 28 Jul 2010, 20:35

Re: Command Button Troubles - Word 2010

Post by heathertank »

Hi Hans -

Thank you -

Unfortunately, the button is still getting deleted. Here's the code I have; please let me know if I did something wrong when I copied.

BTW, I see you did something to my posts to place the code in its own window; if that is something I am able to do, please let me know how. Thanks!

Heather

Code: Select all

Sub InsertInfo()
'
' InsertInfo Macro
'
'
   Selection.MoveDown Unit:=wdLine
    Selection.TypeParagraph
    With Selection.Font
        .Name = "Cambria"
        .Size = 14
        .Bold = True
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = -553598977
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Spacing = 0
        .Scaling = 100
        .Position = 0
        .Kerning = 0
        .Animation = wdAnimationNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    Selection.TypeText Text:="Insert Product Name"
    Selection.TypeParagraph
    Selection.ClearFormatting
    With Selection.Font
        .Name = "Cambria"
        .Size = 12
        .Bold = False
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = wdColorAutomatic
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Spacing = 0
        .Scaling = 100
        .Position = 0
        .Kerning = 0
        .Animation = wdAnimationNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    Selection.TypeText Text:="Insert the opening paragraph about the product."
    Selection.TypeParagraph
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=6, NumColumns:= _
        2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitWindow
    With Selection.Tables(1)
        If .Style <> "Table Grid" Then
            .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
    End With
    Selection.Tables(1).Select
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 6
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Product Number:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Picture:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Description:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Price:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Quantities Available:"
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.Font.Bold = wdToggle
    Selection.TypeText Text:="Volume Discounts"
    Selection.Tables(1).Select
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 6
        .SpaceBeforeAuto = False
        .SpaceAfter = 6
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Move Unit:=wdColumn, Count:=-1
    Selection.SelectColumn
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Move Unit:=wdColumn, Count:=-1
    Selection.SelectColumn
    Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
    Selection.Columns.PreferredWidth = InchesToPoints(2)
    Selection.MoveDown Unit:=wdLine, Count:=1
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 10
        .SpaceBeforeAuto = False
        .SpaceAfter = 10
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceMultiple
        .LineSpacing = LinesToPoints(1.15)
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
    Selection.TypeText Text:= _
        "To order, please visit our website at http://www.northwindtraders.c"
    Selection.TypeText Text:="om."
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdWord, Count:=5, Extend:=wdExtend
    Selection.Copy
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        "http://www.northwindtraders.com/", SubAddress:="", ScreenTip:="", _
        TextToDisplay:="www.northwindtraders.com"
    Selection.MoveDown Unit:=wdLine, Count:=2
    Selection.EndKey Unit:=wdLine
    Selection.TypeParagraph
    Selection.TypeParagraph
End Sub

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command Button Troubles - Word 2010

Post by HansV »

heathertank wrote:BTW, I see you did something to my posts to place the code in its own window; if that is something I am able to do, please let me know how. Thanks!
Yes, it's easy.
Method 1: select the code, then click the Code button above the edit area:
x732.png
This inserts the "tag" [code] before the selected text, and the "tag" [/code] after it.

Method 2: type the tags yourself.

The advantages of the [code] ... [/code] tags are:
- Indentation of the code is preserved.
- If the code is very long, it'll be displayed in a scrolling pane, so that it doesn't take up so much space.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12606
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Command Button Troubles - Word 2010

Post by StuartR »

heathertank wrote:...
BTW, I see you did something to my posts to place the code in its own window; if that is something I am able to do, please let me know how. ...
Simply put
[code]
before your code and
[/code]
after your code
StuartR


User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command Button Troubles - Word 2010

Post by HansV »

When you click the command button, it is the current "Selection". The code starts by moving down one line. The button should then not be selected any more, so that the subsequent code does not replace it. At least, that's how it works in my test document.
Could you post a small sample document without sensitive information that demonstrates the problem?
Best wishes,
Hans

heathertank
NewLounger
Posts: 11
Joined: 28 Jul 2010, 20:35

Re: Command Button Troubles - Word 2010

Post by heathertank »

Hi Hans,

thanks again for your time with this. I am attaching two files; one with the command button inserted in the doc; the other is what the doc looks like after clicking the button. I appreciate any insight!

Heather
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command Button Troubles - Word 2010

Post by HansV »

As you can see in the screenshot below, you have disabled the line

Selection.MoveDown Unit:=wdLine

by inserting an apostrophe before it - this makes it a comment.
x153.png
As a consequence, the command button is still selected when the next line

Selection.TypeParagraph

is executed. This replaces the command button with a paragraph mark. You should "uncomment" the line mentioned above by removing the apostrophe:
x154.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

heathertank
NewLounger
Posts: 11
Joined: 28 Jul 2010, 20:35

Re: Command Button Troubles - Word 2010

Post by heathertank »

Oh, so simple. Thank you Hans. I am definitely jumping in to editing the VB without having much background in writing it. That makes perfect sense to me - I appreciate you pointing this out. Thanks again!

Heather

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Command Button Troubles - Word 2010

Post by HansV »

What probably happened: the apostrophe was already there, it was created by Word when you recorded the macro. By accident, you didn't paste the lines into a blank line, but into the line that consisted of a single apostrophe. Hence the first of the two lines that you pasted became a comment.
Best wishes,
Hans