Zephid15
04-30-2007, 06:28 AM
I have written a form that has the price and description of a product. now when the user selects one of the products and presses the continue button i want the program to take that data and construct a nice table on a word document. have a good amount of it written although i am having issues moving from cell to cell within the table. is there a better way do do this?
heres the code i have so far. i have not written all of the move commands in but, when i went to test what i have so far it has been giving me an error message at the "Selection.MoveDown Unit:=wdCell" parts.
Thanks for your help.
Dave
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=3, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.Font.Size = 10
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="1)"
Selection.MoveRight Unit:=wdCell
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Name"
Selection.MoveRight Unit:=wdCell
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Number"
Selection.MoveDown Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.Font.Size = 8
Selection.TypeText Text:="DESC"
Selection.MoveRight Unit:=wdCell
Selection.InlineShapes.AddPicture FileName:= _
"C:\Documents and Settings\dl134880\Desktop\clip_image002.jpg", _
LinkToFile:=False, SaveWithDocument:=True
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.MoveDown Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.Cells.Split NumRows:=1, NumColumns:=5, MergeBeforeSplit:=False
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.Cells.Split NumRows:=1, NumColumns:=5, MergeBeforeSplit:=False
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.TypeText Text:="QTY"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="qty"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="UNIT"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="unit"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="TOTAL"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="total"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="DIS"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="dis"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="NET"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="net"
Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
ActiveWindow.ActivePane.VerticalPercentScrolled = 25
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorGray45
Selection.Font.Color = wdColorBlack
Selection.Font.Color = wdColorWhite
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=13, Extend:=wdExtend
Selection.Font.Size = 8
Selection.Cells.DistributeWidth
ActiveWindow.ActivePane.VerticalPercentScrolled = 25
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cells.DistributeHeight
End If
Unload Me
End Sub
heres the code i have so far. i have not written all of the move commands in but, when i went to test what i have so far it has been giving me an error message at the "Selection.MoveDown Unit:=wdCell" parts.
Thanks for your help.
Dave
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=3, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.Font.Size = 10
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="1)"
Selection.MoveRight Unit:=wdCell
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Name"
Selection.MoveRight Unit:=wdCell
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Number"
Selection.MoveDown Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.Font.Size = 8
Selection.TypeText Text:="DESC"
Selection.MoveRight Unit:=wdCell
Selection.InlineShapes.AddPicture FileName:= _
"C:\Documents and Settings\dl134880\Desktop\clip_image002.jpg", _
LinkToFile:=False, SaveWithDocument:=True
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.MoveDown Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.Cells.Split NumRows:=1, NumColumns:=5, MergeBeforeSplit:=False
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.Cells.Split NumRows:=1, NumColumns:=5, MergeBeforeSplit:=False
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.MoveLeft Unit:=wdCell
Selection.TypeText Text:="QTY"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="qty"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="UNIT"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="unit"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="TOTAL"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="total"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="DIS"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="dis"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="NET"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="net"
Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
ActiveWindow.ActivePane.VerticalPercentScrolled = 25
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorGray45
Selection.Font.Color = wdColorBlack
Selection.Font.Color = wdColorWhite
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=13, Extend:=wdExtend
Selection.Font.Size = 8
Selection.Cells.DistributeWidth
ActiveWindow.ActivePane.VerticalPercentScrolled = 25
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cells.DistributeHeight
End If
Unload Me
End Sub