Command Button Macro not working HELP!

titan2x

New Member
Joined
Sep 27, 2006
Messages
6
I attached this macro to a command button and it will not run. It worked before I tried placing it onto a button. Please Help!

Below is the macro:
Private Sub CommandButton1_Click()
Dim appWD As Word.Application
' Create a new instance of Word & make it visible
Set appWD = CreateObject("Word.Application.11")
appWD.Visible = True
Sheets("Customer").Select
'Copy the data for the new document to the clipboard
Range("A1:L113").Copy
' Tell Word to create a new document
appWD.Documents.Add
' Tell Word to paste the contents of the clipboard into the new document
appWD.Selection.Paste
' Setup margins accordingly
appWD.Selection.PageSetup.TopMargin = InchesToPoints(0.22)
appWD.Selection.PageSetup.BottomMargin = InchesToPoints(0.22)
appWD.Selection.PageSetup.LeftMargin = InchesToPoints(0.25)
appWD.Selection.PageSetup.RightMargin = InchesToPoints(0.13)
appWD.ActiveDocument.Shapes("Picture 2").Select
appWD.Selection.ShapeRange.Fill.Visible = msoFalse
appWD.Selection.ShapeRange.Fill.Solid
appWD.Selection.ShapeRange.Fill.Transparency = 0#
appWD.Selection.ShapeRange.Line.Weight = 0.75
appWD.Selection.ShapeRange.Line.DashStyle = msoLineSolid
appWD.Selection.ShapeRange.Line.Style = msoLineSingle
appWD.Selection.ShapeRange.Line.Transparency = 0#
appWD.Selection.ShapeRange.Line.Visible = msoFalse
appWD.Selection.ShapeRange.LockAspectRatio = msoTrue
appWD.Selection.ShapeRange.Rotation = 0#
appWD.Selection.ShapeRange.PictureFormat.Brightness = 0.5
appWD.Selection.ShapeRange.PictureFormat.Contrast = 0.5
appWD.Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic
appWD.Selection.ShapeRange.PictureFormat.CropLeft = 0#
appWD.Selection.ShapeRange.PictureFormat.CropRight = 0#
appWD.Selection.ShapeRange.PictureFormat.CropTop = 0#
appWD.Selection.ShapeRange.PictureFormat.CropBottom = 0#
appWD.Selection.ShapeRange.Left = 18#
appWD.Selection.ShapeRange.Top = 72#
appWD.Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionMargin
appWD.Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionParagraph
appWD.Selection.ShapeRange.Left = InchesToPoints(0.4)
appWD.Selection.ShapeRange.Top = InchesToPoints(0)
appWD.Selection.ShapeRange.LockAnchor = False
appWD.Selection.ShapeRange.LayoutInCell = True
appWD.Selection.ShapeRange.WrapFormat.AllowOverlap = False
appWD.Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
appWD.Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
appWD.Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
appWD.Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
appWD.Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
appWD.Selection.ShapeRange.WrapFormat.Type = 3
appWD.Selection.ShapeRange.ZOrder 4
appWD.ActiveWindow.ActivePane.VerticalPercentScrolled = 36
appWD.ActiveDocument.Shapes("Picture 3").Select
appWD.Selection.ShapeRange.Fill.Visible = msoFalse
appWD.Selection.ShapeRange.Fill.Solid
appWD.Selection.ShapeRange.Fill.Transparency = 0#
appWD.Selection.ShapeRange.Line.Weight = 0.75
appWD.Selection.ShapeRange.Line.DashStyle = msoLineSolid
appWD.Selection.ShapeRange.Line.Style = msoLineSingle
appWD.Selection.ShapeRange.Line.Transparency = 0#
appWD.Selection.ShapeRange.Line.Visible = msoFalse
appWD.Selection.ShapeRange.LockAspectRatio = msoTrue
appWD.Selection.ShapeRange.Rotation = 0#
appWD.Selection.ShapeRange.PictureFormat.Brightness = 0.5
appWD.Selection.ShapeRange.PictureFormat.Contrast = 0.5
appWD.Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic
appWD.Selection.ShapeRange.PictureFormat.CropLeft = 0#
appWD.Selection.ShapeRange.PictureFormat.CropRight = 0#
appWD.Selection.ShapeRange.PictureFormat.CropTop = 0#
appWD.Selection.ShapeRange.PictureFormat.CropBottom = 0#
appWD.Selection.ShapeRange.Left = 18#
appWD.Selection.ShapeRange.Top = 161.25
appWD.Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionMargin
appWD.Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionParagraph
appWD.Selection.ShapeRange.Left = InchesToPoints(0.4)
appWD.Selection.ShapeRange.Top = InchesToPoints(0)
appWD.Selection.ShapeRange.LockAnchor = False
appWD.Selection.ShapeRange.LayoutInCell = True
appWD.Selection.ShapeRange.WrapFormat.AllowOverlap = False
appWD.Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
appWD.Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
appWD.Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
appWD.Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
appWD.Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
appWD.Selection.ShapeRange.WrapFormat.Type = 3
appWD.Selection.ShapeRange.ZOrder 4
appWD.Selection.HomeKey Unit:=wdLine
appWD.Selection.InsertBreak Type:=wdPageBreak
appWD.Selection.MoveUp Unit:=wdScreen, Count:=4


End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
Can you define, "will not run." a little better?
Does the macro start?
Getting any errors? If so, what are they?
Is the name of your command button "CommandButton1"?
Did you set a reference to Microsoft Word Object Library in VBA?
 

Forum statistics

Threads
1,141,678
Messages
5,707,780
Members
421,527
Latest member
Tamiwsw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top