Click here to Skip to main content
15,877,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a program in to create and automate a Word document.

I am adding a command button to the document, and giving it parameters:

'************ CommandButton 1
			Dim shp As Word.InlineShape
			Dim sPrinter As String = z.Printer
			Dim wdShapeRight As String = ""
			Dim wdRelativeHorizontalPositionMargin As String = ""
			shp = oMainDoc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1")
			shp.OLEFormat.Object.AutoSize = False
			shp.OLEFormat.Object.WordWrap = True
			shp.OLEFormat.Object.Caption = sPrinter
			Dim tShp As word.Shape
			Dim tTest As Integer =0
			tShp = shp.ConvertToShape()
			tShp.OLEFormat.Object.Name = "ATPbutton1"
			tshp.OLEFormat.Object.wordwrap = True
			tshp.OLEFormat.Object.Caption = sPrinter
			tShp.OLEFormat.Object.Font.Name = "Times New Roman"
			tShp.OLEFormat.Object.Font.Size = 10
			tShp.OLEFormat.Object.BackColor = WdColor.wdColorPaleBlue
			tShp.OLEFormat.Object.AutoSize = False
			Dim dWidth As Integer = oMainDoc.ActiveWindow.Document.PageSetup.PageWidth
			Dim dRMargin As Integer = oMainDoc.ActiveWindow.Document.PageSetup.RightMargin
			tShp.OLEFormat.Object.Width = len(sPrinter)+100
			Dim cWidth As Integer = tshp.OLEFormat.Object.Width
			Dim cLeft As Integer = dWidth - dRMargin - cWidth
			tShp.OLEFormat.Object.Left = cLeft
			tShp.OLEFormat.Object.Top = 80
			tShp.OLEFormat.Object.Height = 30

When I run the program in SharpDevelop, it runs just fine.

However, when I compile and run this program, the program crashes. The line that is crashing the program is:

Dim shp As Word.InlineShape

Any ideas?
Casey Sheridan 3-Jul-12 7:41am    
I'm not sure how to answer your question but I would suggest that you take the first part of you question out of the "code" brackets.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900