'#Reference {00020905-0000-0000-C000-000000000046}#8.1#0#C:\Program Files\Microsoft Office\Office\MSWORD9.OLB#Microsoft Word 9.0 Object Library Option Explicit ' last tested with 13.3.0.10 Public Sub WordOpSheet 'Public Sub main Dim MSWord As Word.Application Dim Doc As Word.Document Dim OpSheet As Word.Table Dim SQL As String Dim LastDate As Date Dim Result As Boolean Dim FMDoc As MFGDocument Set FMDoc = Application.ActiveDocument Set MSWord = New Word.Application MSWord.Visible = True Set Doc = MSWord.Documents.Add ' select entire document MSWord.Selection.WholeStory ' delete entire selection MSWord.Selection.Delete ' turn on table gridlines MSWord.ActiveWindow.View.TableGridlines = True ' set font size to 22 points 'MSWord.Selection.Font.Size = 22 ' set font color to red 'MSWord.Selection.Font.ColorIndex = wdRed ' use wdAuto to turn it back 'MSWord.Selection.TypeText "Your Account details:" & vbNewLine 'MSWord.Selection.TypeParagraph 'MSWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter 'MSWord.Selection.Font.Size = 12 ' add table and format it Dim Rows As Integer Rows = FMDoc.Operations.Count + 7 'Added 7 extra rows to account for the headers Set OpSheet = Doc.Tables.Add(MSWord.Selection.Range, Rows, 8) OpSheet.PreferredWidthType = wdPreferredWidthPercent OpSheet.PreferredWidth = 100 ' MSWord.InchesToPoints(6) OpSheet.AutoFormat wdTableFormatNone OpSheet.Columns(1).Width = MSWord.InchesToPoints(0.5) OpSheet.Columns(2).Width = MSWord.InchesToPoints(1) OpSheet.Columns(3).Width = MSWord.InchesToPoints(1.4) OpSheet.Columns(4).Width = MSWord.InchesToPoints(0.6) OpSheet.Columns(5).Width = MSWord.InchesToPoints(0.5) OpSheet.Columns(6).Width = MSWord.InchesToPoints(1) OpSheet.Columns(7).Width = MSWord.InchesToPoints(0.5) OpSheet.Columns(8).Width = MSWord.InchesToPoints(0.7) OpSheet.Rows.AllowBreakAcrossPages = False 'OpSheet.AutoFitBehavior(wdAutoFitWindow) 'OpSheet.AllowAutoFit = True 'OpSheet.Columns(2).Width = MSWord.CentimetersToPoints(3) Dim firstrow As Integer firstrow = 1 ' merge the first row OpSheet.Rows(firstrow).Cells.Merge ' set some shading on the first row OpSheet.Rows(firstrow).Shading.Texture = wdTexture10Percent ' set a title OpSheet.Rows(firstrow).Range.text = "XYZ Engineering" OpSheet.Rows(firstrow).Range.Font.Size = 22 ' center the title OpSheet.Rows(firstrow).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter ' make it bold OpSheet.Rows(firstrow).Range.Bold = True firstrow = firstrow + 1 ' merge the first row OpSheet.Rows(firstrow).Cells.Merge ' set some shading on the first row OpSheet.Rows(firstrow).Shading.Texture = wdTexture10Percent ' set a title OpSheet.Rows(firstrow).Range.text = "Manufacturing Operations Sheet" OpSheet.Rows(firstrow).Range.Font.Size = 22 ' center the title OpSheet.Rows(firstrow).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter ' make it bold OpSheet.Rows(firstrow).Range.Bold = True firstrow = firstrow + 1 Call OpSheet.Cell(firstrow, 5).Merge(OpSheet.Cell(firstrow, 8)) Call OpSheet.Cell(firstrow, 1).Merge(OpSheet.Cell(firstrow, 4)) OpSheet.Cell(firstrow, 1).Range.text = "Part file: " & FMDoc.Name OpSheet.Cell(firstrow, 2).Range.text = "NC Program Name: " & FMDoc.PartName OpSheet.Rows(firstrow).Range.Bold = True firstrow = firstrow + 1 Call OpSheet.Cell(firstrow, 5).Merge(OpSheet.Cell(firstrow, 8)) Call OpSheet.Cell(firstrow, 1).Merge(OpSheet.Cell(firstrow, 4)) OpSheet.Cell(firstrow, 1).Range.text = "Units: " & IIf( FMDoc.Metric = True, "MM", "Inch" ) If TypeName( FMDoc ) = "IFMDocument" Then OpSheet.Cell(firstrow, 2).Range.text = "Material: " & FMDoc.Stock.Material End If OpSheet.Rows(firstrow).Range.Bold = True firstrow = firstrow + 1 Call OpSheet.Cell(firstrow, 5).Merge(OpSheet.Cell(firstrow, 8)) Call OpSheet.Cell(firstrow, 1).Merge(OpSheet.Cell(firstrow, 4)) If TypeName( FMDoc ) = "IFMDocument" Then OpSheet.Cell(firstrow, 1).Range.text = "Setup: " & FMDoc.ActiveSetup End If OpSheet.Cell(firstrow, 2).Range.text = "Date: " & Date OpSheet.Rows(firstrow).Range.Bold = True firstrow = firstrow + 1 Call OpSheet.Cell(firstrow, 5).Merge(OpSheet.Cell(firstrow, 8)) Call OpSheet.Cell(firstrow, 1).Merge(OpSheet.Cell(firstrow, 4)) Dim length As Double, wid As Double, thick As Double Dim od As Double, id As Double, nsides As Long Dim axisType As tagFMAxisType Dim stockCurve As String Dim stockType As tagFMStockType If TypeName( FMDoc ) = "IFMDocument" Then FMDoc.Stock.GetDimensions( stockType, length, wid, thick, od, id, axisType, nsides, stockCurve ) OpSheet.Cell(firstrow, 1).Range.text = "Stock Size: L" & length & " W" & wid & " T" & thick End If OpSheet.Cell(firstrow, 2).Range.text = "" OpSheet.Rows(firstrow).Range.Bold = True firstrow = firstrow + 1 ' Populate Table OpSheet.Cell(firstrow, 1).Range.text = "Op #" OpSheet.Cell(firstrow, 2).Range.text = "Type" OpSheet.Cell(firstrow, 3).Range.text = "Feature" OpSheet.Cell(firstrow, 4).Range.text = "RPM" OpSheet.Cell(firstrow, 5).Range.text = "Feed" OpSheet.Cell(firstrow, 6).Range.text = "Tool Name" OpSheet.Cell(firstrow, 7).Range.text = "Tool Slot" OpSheet.Cell(firstrow, 8).Range.text = "Depth" OpSheet.Rows(firstrow).Range.Bold = True firstrow = firstrow + 1 'OpSheet.Cell(firstRow + 1, 1).Range.Text = "T:" 'OpSheet.Cell(firstRow + 1, 2).Range.Text = 50 'OpSheet.Cell(firstRow + 2, 1).Range.Text = "A:" 'OpSheet.Cell(firstRow + 2, 2).Range.Text = 100 ' make the last cell be a total 'OpSheet.Cell(firstRow + 3, 2).Select 'MSWord.Selection.InsertFormula Formula:="=SUM(ABOVE)", NumberFormat:="#,##0.00" ' turn on borders of the table With OpSheet.Borders .InsideLineStyle = wdLineStyleSingle .OutsideLineStyle = wdLineStyleDouble End With Dim oper As FMOperation, tool As FMToolMap, slot As Long Dim i As Integer i = 0 For Each oper In FMDoc.Operations OpSheet.Cell(firstrow + i, 1 ) = CStr( i + 1 ) OpSheet.Cell(firstrow + i, 2 ) = oper.OperationName OpSheet.Cell(firstrow + i, 3 ) = oper.FeatureName OpSheet.Cell(firstrow + i, 8 ) = oper.DepthText If Not (oper.Tool Is Nothing) Then 'Tool is empty if the operation has no tool like a subspindle operation 'or there are problems and the tool cannot be read For Each tool In FMDoc.ToolMaps If (tool.Tool = oper.Tool) Then slot=tool.ToolNumber Exit For End If Next OpSheet.Cell(firstrow + i, 4 ) = oper.SpeedText OpSheet.Cell(firstrow + i, 5 ) = oper.FeedText OpSheet.Cell(firstrow + i, 6 ) = oper.Tool.Name OpSheet.Cell(firstrow + i, 7 ) = CStr(slot) End If i = i + 1 Next ' save preview picture FMDoc.Sim3D '3d simulation FMDoc.SetView(eVT_Isometric) FMDoc.SetView(eVT_CenterAll) Wait 0.5 'value in seconds, needs to wait here so that picture works correctly Dim part_doc As FMPartDoc Set part_doc = FMDoc.PartDocumentation part_doc.SetPreviewPicture 'Set the current contents of the FeatureCAM graphics window as the preview picture for the FeatureCAM document part_doc.SavePreviewPictureAsFile("C:\preview.png") ' Insert picture Doc.Tables(1).Range.InsertParagraphBefore Doc.InlineShapes.AddPicture("c:\preview.png") End Sub ' Add a toolbar and buttons upon loading of this addin into FeatureCAM. ' Private Sub AddIn_OnConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) ' Bar name Button name Button face ID MakeButtonAndBar "Utilities", "WordOpSheet", 42 End Sub ' ' remove button or hide toolbar if add-in deselected ' Private Sub AddIn_OnDisConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) HideDeleteBarButton "Utilities", "WordOpSheet" End Sub Private Sub MakeButtonAndBar(ByVal bar_name As String, ByVal button_name As String, _ ByVal button_id As Integer) Dim bars As FMCmdBars, bar As FMCmdBar, ctrl As FMCmdBarBtn Set bars = Application.CommandBars Set bar = bars(bar_name) If bar Is Nothing Then Set bar = bars.Add(bar_name) Else bar.Visible = True End If Set ctrl = bar.Controls(button_name) If ctrl Is Nothing Then Set ctrl = bar.Controls.Add( ,,button_name) ctrl.FaceId = button_id bar.Visible = True End If End Sub Private Sub HideDeleteBarButton(ByVal bar_name As String, ByVal button_name As String) Dim bars As FMCmdBars, bar As FMCmdBar, ctrl As FMCmdBarCtrl Set bars = Application.CommandBars Set bar = bars(bar_name) If Not bar Is Nothing Then Set ctrl = bar.Controls(button_name) If Not ctrl Is Nothing Then If bar.Controls.Count > 1 Then ctrl.Delete Else bar.Visible=False End If End If End If End Sub