Ho to select one spreadsheet after another in LibreOffice? - select

How to select spreadsheets one after another in Libre Office to perform some action in them?
In excel vba the following code worked, but it does not work in LibreOffice
Dim wb as Workbook
Dim ws as Worksheet
Set wb = ActiveWorkbook
For Each ws in wb.Worksheets
'Do something here
End if
Next
Could anyone help me with that?

First of all get the oSheets object (which is what is called Worksheets in Excel) of ThisComponent (which is what is called ActiveWorkbook in Excel)
Sub sheetProcessing()
Dim oSheets As Variant, oSheet As Variant
Dim i As Long
' By Sheet index
oSheets = ThisComponent.getSheets()
For i = 0 To oSheets.getCount() - 1
oSheet = oSheets.getByIndex(i)
Print oSheet.getName() & " - " & oSheet.getCellByPosition(0, 0).getString()
Next i
' Or by Element Names
Dim oElementNames As Variant
oElementNames = oSheets.getElementNames()
For i = LBound(oElementNames) To UBound(oElementNames)
oSheet = oSheets.getByName(oElementNames(i))
Print oSheet.getName() & " - " & oSheet.getCellByPosition(0, 0).getString()
Next i
' Or easiest
For Each oSheet In oSheets
Print oSheet.getName() & " - " & oSheet.getCellByPosition(0, 0).getString()
Next oSheet
End Sub

Related

Macro for Saving Solidworks part configurations as dxf files

I have to save a lot of dxf files from Solidworks to use for a CNC machine.
I'm looking for help to create a macro to save each configuration of the part as the top view of a part as a .dxf in the same location as the Solidworks file is saved.
I have found two macros which I kind of need to be combined together.
The first one saves all configurations separately as part files
The second one saves a part as a dxf of the top view.
It would be much appreciated if anyone could help me
first macro:
' Macro created by Jeff Parker CSWP/MCP 12/30/02
'
' Rev.1 = Added completion message box. Also verified SolidWorks 2005 compatabliity.
'
' Rev.2 = Fixed macro for x64 bits machines (changed folder browse codes). Also verified SolidWorks 2014 compatabliity.
' (BY: Deepak Gupta www.gupta9665.com 07/26/14)
' Folder Browse Codes: http://www.cpearson.com/excel/browsefolder.aspx
'
' Rev.3 = Fixed macro for Weldment part configuration names having <As Machined> and <As Welded>. Also verified SolidWorks 2016 compatabliity.
' (BY: Deepak Gupta www.gupta9665.com 01/14/16)
'
' DISCLAIMER:
' * These macros are provided free of charge for personal use and/or reference.
' * These macros may be freely distributed, provided the original copyright
' notices remain unchanged and intact.
' * All macros were written to work with SolidWorks 2005.
' * These macros, and corresponding files, are provided as is.
' * There are no warranties, expressed or implied, that these macros will perform
' as indicated, perform to users expectations, or complete a specific task.
' * These macros will change the current SolidWorks document. Use these macros at
' your own risk. Back up your data before using this macro on any SolidWorks
' document.
'
' ******************************************************************************
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long
Dim Annotation As Object
Dim Gtol As Object
Dim DatumTag As Object
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Dim ConfigNamesArray As Variant
Dim ConfigNameMain As Variant
Dim ConfigName As Variant
Dim NewName As String
Dim PartName As String
Dim OpenName As String
Dim CurrentConfigName As Variant
Dim fileerror As Long
Dim filewarning As Long
Dim OrigConfigName As Variant
Dim Location As Variant
Dim ModLoc As String
Dim MassProps As Variant
Dim Mass As Variant
Dim MassError As Long
Dim ConfigCount As Long
Dim MassPropArrayTest As Long
Dim CustomPropNamesArray As Variant
Dim CustomPropName As Variant
Dim PartSourceName As String
Dim PartSourcePath As String
Dim status As Boolean
Sub main()
Set swApp = Application.SldWorks 'Connect to SolidWorks session
Set Part = swApp.ActiveDoc 'Set Part variable to active doc
If Part Is Nothing Then Exit Sub
ConfigCount = Part.GetConfigurationCount 'Get number of configurations
PartSourceName = Part.GetTitle 'Get name of original part file that contains configurations
If Part.GetType <> swDocPART Then 'Check to see if current document is a part
MsgBox "Only Allowed on Parts, Please open a part and try again.", vbOKOnly, "Error" ' Display error message"
Exit Sub ' Exit this program
ElseIf ConfigCount = 1 Then
MsgBox "Must have at least two configurations before starting macro.", vbOKOnly, "Error" ' Display error message"
Exit Sub ' Exit this program
Else
GoTo Rip
End If
Rip: 'RIP sub section
frmLocation.Show 'Show form
Location = frmLocation.txtPath.Text 'Get user selected location
'---Check to see if location has last backslash---
ModLoc = Right(Location, 1)
If ModLoc <> "\" Then
Location = Location & "\"
End If
ConfigNamesArray = Part.GetConfigurationNames 'Populate the array with all config names
OrigConfigName = ConfigNamesArray(0) 'Get current configuration
For i = 0 To UBound(ConfigNamesArray)
ConfigName = ConfigNamesArray(i) 'Assign next config name to ConfigName variable
Part.ShowConfiguration2 (ConfigName) 'Set next config as current
ConfigName = Replace((Replace(ConfigName, "<As Machined>", "")), "<As Welded>", "")
NewName = Location & ConfigName & ".sldprt" 'Create path
Part.SaveAsSilent NewName, True 'Save as current config name
Next i
PartSourcePath = Part.GetPathName
swApp.CloseDoc PartSourceName 'Close the source file to conserve memory for program
Set Part = Nothing 'Clear part variable
For j = 0 To UBound(ConfigNamesArray)
ConfigNameMain = ConfigNamesArray(j) 'Populate ConfigNameMain with current name
ConfigNameMain = Replace((Replace(ConfigNameMain, "<As Machined>", "")), "<As Welded>", "")
OpenName = Location & ConfigNameMain & ".sldprt" 'Set location of file to open
fileerror = swFileNotFoundError 'Default system error message
filewarning = swFileSaveWarning_NeedsRebuild 'Default warning message
swApp.OpenDoc6 OpenName, 1, 0, "", fileerror, filewarning 'Open saved configuration file
Set Part = swApp.ActiveDoc 'Set newly opened file as current
Part.DeleteDesignTable 'Delete design table if present
For k = 0 To UBound(ConfigNamesArray) 'Delete all configurations from new file
ConfigName = ConfigNamesArray(k)
Part.DeleteConfiguration2 (ConfigName)
Next k
Part.EditConfiguration3 ConfigNameMain, "Default", "", "", 0 'Rename leftover config to default
Part.ViewZoomtofit2 'Make part zoom to fit so icon looks good
Part.Save2 (True) 'Save newly modified part
Set Part = Nothing 'Clear Part variable
swApp.CloseDoc ConfigNameMain & ".sldprt" 'Close current part
Next j
swApp.OpenDoc6 PartSourcePath, 1, 0, "", fileerror, filewarning 'Open original source file
Set Part = swApp.ActiveDoc 'Set original part as current
Part.ShowConfiguration2 (OrigConfigName) 'Set original part to original status
MsgBox "Here is where you can find your files: " & Chr(13) & Location, vbInformation, "Configuration Rip Success!"
Location = "" 'Clear location variable
End Sub 'Close program
second macro:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim sModelName As String
Dim sPathName As String
Dim varAlignment As Variant
Dim dataAlignment(11) As Double
Dim varViews As Variant
Dim dataViews(0) As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
sModelName = swModel.GetPathName
sPathName = Left(sModelName, Len(sModelName) - 6) & "dxf"
dataAlignment(0) = 0#
dataAlignment(1) = 0#
dataAlignment(2) = 0#
dataAlignment(3) = 1#
dataAlignment(4) = 0#
dataAlignment(5) = 0#
dataAlignment(6) = 0#
dataAlignment(7) = 0#
dataAlignment(8) = -1#
dataAlignment(9) = 0#
dataAlignment(10) = 1#
dataAlignment(11) = 0#
varAlignment = dataAlignment
dataViews(0) = "*Top"
varViews = dataViews
swPart.ExportToDWG2 sPathName, sModelName, swExportToDWG_e.swExportToDWG_ExportAnnotationViews, True, varAlignment, False, False, 0, varViews
End Sub
Try the following codes which exports each configuration of the active part as DXF.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim sModelName As String
Dim sPathName As String
Dim vConfNameArr As Variant
Dim i As Long
Dim sConfigName As String
Dim bRebuild As Boolean
Dim swPart As SldWorks.PartDoc
Dim nFileName As String
Dim varAlignment As Variant
Dim dataAlignment(11) As Double
Dim varViews As Variant
Dim dataViews(0) As String
Sub Main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Is document active?
If swModel Is Nothing Then
swApp.SendMsgToUser2 "A Sheet Metal Part must be open.", swMbWarning, swMbOk
Exit Sub
End If
' Is it a part document?
If swModel.GetType <> SwConst.swDocPART Then
swApp.SendMsgToUser2 "A Sheet Metal Part must be open.", swMbWarning, swMbOk
Exit Sub
End If
sModelName = swModel.GetPathName
sPathName = Left(sModelName, InStrRev(sModelName, "\"))
vConfNameArr = swModel.GetConfigurationNames
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
If Not UCase(sConfigName) Like "*FLAT*" Then
swModel.ShowConfiguration2 (sConfigName)
bRebuild = swModel.ForceRebuild3(False)
nFileName = sPathName & sConfigName & ".DXF"
Set swPart = swModel
dataAlignment(0) = 0#
dataAlignment(1) = 0#
dataAlignment(2) = 0#
dataAlignment(3) = 0#
dataAlignment(4) = 0#
dataAlignment(5) = 0#
dataAlignment(6) = 0#
dataAlignment(7) = 0#
dataAlignment(8) = 0#
dataAlignment(9) = 0#
dataAlignment(10) = 0#
dataAlignment(11) = 0#
varAlignment = dataAlignment
dataViews(0) = "*Top"
varViews = dataViews
'Export Top View
swPart.ExportToDWG2 nFileName, sModelName, 3, True, varAlignment, False, False, 0, varViews
End If
Next i
End Sub

Extract text content from PPT and output file as a word doc

Taken dis codes from random sites using for extract the text content in Slide and Notes section from PPT slides. But the output file given as a NOTEPAD. I want the o/p file as a word document. Can anyone to help on this? Thanks to you in advance
P.S. I express my gratitude those who created these codes and simplify my work.
Option Explicit
Sub ExportNotesText()
Dim oSlides As Slides
Dim oSl As Slide
Dim oSh As Shape
Dim strNotesText As String
Dim strFileName As String
Dim intFileNum As Integer
Dim lngReturn As Long
' Get a filename to store the collected text
strFileName = InputBox("Enter the full path and name of file to extract notes text to", "Output file?")
' did user cancel?
If strFileName = "" Then
Exit Sub
End If
' is the path valid? crude but effective test: try to create the file.
intFileNum = FreeFile()
On Error Resume Next
Open strFileName For Output As intFileNum
If Err.Number <> 0 Then ' we have a problem
MsgBox "Couldn't create the file: " & strFileName & vbCrLf _ & "Please try again."
Exit Sub
End If
Close #intFileNum ' temporarily
' Get the notes text
Set oSlides = ActivePresentation.Slides
For Each oSl In oSlides
strNotesText = strNotesText & "======================================" & vbCrLf
strNotesText = strNotesText & "Slide" & oSl.SlideIndex & vbCrLf
strNotesText = strNotesText & SlideText(oSl) & vbCrLf
strNotesText = strNotesText & NotesText(oSl) & vbCrLf
Next oSl
' now write the text to file
Open strFileName For Output As intFileNum
Print #intFileNum, strNotesText
Close #intFileNum
' show what we've done
lngReturn = Shell("NOTEPAD.EXE " & strFileName, vbNormalFocus)
End Sub
Function SlideText(oSl As Slide) As String
Dim oSh As Shape
Dim osld As Slide
Dim strNotesText As String
For Each oSh In oSl.Shapes
If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
SlideText = SlideText & oSh.Name & ":" & " " & oSh.TextFrame.TextRange & vbCrLf
End If
End If
Next oSh
End Function
Function NotesText(oSl As Slide) As String
Dim oSh As Shape
For Each oSh In oSl.NotesPage.Shapes
If oSh.PlaceholderFormat.Type = ppPlaceholderBody Then
If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
NotesText = oSh.TextFrame.TextRange.Text
End If
End If
End If
Next oSh
End Function
For Example:
Sub Demo()
'Note: A VBA Reference to Word is required.
'See under Tools|References
Dim WdApp As New Word.Application, wdDoc As Word.Document
Dim Sld As Slide, Shp As Shape
Set wdDoc = WdApp.Documents.Add
For Each Sld In ActivePresentation.Slides
With Sld
For Each Shp In .NotesPage.Shapes
With Shp
If .PlaceholderFormat.Type = ppPlaceholderBody Then
If .HasTextFrame Then
If .TextFrame.HasText Then
wdDoc.Range.InsertAfter vbCr & Sld.SlideIndex & ": " & .TextFrame.TextRange.Text
End If
End If
End If
End With
Next
For Each Shp In .Shapes
With Shp
If .HasTextFrame Then
If .TextFrame.HasText Then
wdDoc.Range.InsertAfter vbCr & .Name & ": " & .TextFrame.TextRange.Text
End If
End If
End With
Next
End With
Next
WdApp.Visible = True: wdDoc.Activate
Set wdDoc = Nothing: Set WdApp = Nothing
End Sub

Export Table in Query to email VBA

I'm trying to export one of my queries to email using VBA in a table format. Similar to when you go to external data and click and E-Mail and it adds an attachment to outlook. Except I want it in the body. I put the following code in a button.
I found and made some changes to some code. This is what I have.
Private Sub Command5_Click()
Dim olApp As Object
Dim olItem As Variant
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim strQry As String
Dim aHead(1 To 4) As String
Dim aRow(1 To 4) As String
Dim aBody() As String
Dim lCnt As Long
'Create the header row
aHead(1) = "Part"
aHead(2) = "Description"
aHead(3) = "Qty"
aHead(4) = "Price"
lCnt = 1
ReDim aBody(1 To lCnt)
aBody(lCnt) = "<HTML><body><table border='2'><tr><th>" & Join(aHead, "</th> <th>") & "</th></tr>"
'Create each body row
strQry = "SELECT * From qry_email"
Set db = CurrentDb
Set rec = CurrentDb.OpenRecordset(strQry)
If Not (rec.BOF And rec.EOF) Then
Do While Not rec.EOF
lCnt = lCnt + 1
ReDim Preserve aBody(1 To lCnt)
aRow(1) = rec("Part")
aRow(2) = rec("Description")
aRow(3) = rec("Qty")
aRow(4) = rec("Price")
aBody(lCnt) = "<tr><td>" & Join(aRow, "</td><td>") & "</td></tr>"
rec.MoveNext
Loop
End If
aBody(lCnt) = aBody(lCnt) & "</table></body></html>"
'create the email
Set olApp = CreateObject("Outlook.application")
Set olItem = olApp.CreateItem(0)
olItem.Display
olItem.To = "email#email.com"
olItem.Subject = "Test E-mail"
olItem.HTMLBody = Join(aBody, vbNewLine)
olItem.Display
End Sub
When I run the code, I get a "Run-time error '3061' too few parameters. Expected 1."
If i click debug i get this highlighted in yellow. Anybody help would be greatly appreciated!
Edit
I tried a different approach which actually gave me the list in the body of the email. But it does it for the whole table instead of just the one record I want. This is what the SQL looks like of the query.
SELECT tblePMParts.[Part#], tblePMParts.PartDescription, tblePMParts.Qty, tblePMParts.Price
FROM tblePMParts
WHERE (((tblePMParts.WOID)=[Forms]![fmremail]![Text1]));
How would I go about adding the WHERE to the code below.
Private Sub Command4_Click()
'On Error GoTo Errorhandler
Dim olApp As Object
Dim olItem As Variant
Dim olatt As String
Dim olMailTem As Variant
Dim strSendTo As String
Dim strMsg As String
Dim strTo As String
Dim strcc As String
Dim rst As DAO.Recordset
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim qry As DAO.QueryDef
Dim fld As Field
Dim varItem As Variant
Dim strtable As String
Dim rec As DAO.Recordset
Dim strQry As String
strQry = "SELECT tblePMParts.[Part#], tblePMParts.PartDescription, tblePMParts.Qty, tblePMParts.Price " & _
"FROM tblePMParts; "
strSendTo = "test#email.com"
strTo = ""
strcc = ""
Set olApp = CreateObject("Outlook.application")
Set olItem = olApp.CreateItem(olMailTem)
olItem.Display
olItem.To = strTo
olItem.CC = strcc
olItem.Body = ""
olItem.Subject = "Please Quote the Following!"
Set db = CurrentDb
Set rec = CurrentDb.OpenRecordset(strQry)
If Not (rec.BOF And rec.EOF) Then
rec.MoveLast
rec.MoveFirst
intCount = rec.RecordCount
For intLoop = 1 To intCount
olItem.Body = olItem.Body & rec("[Part#]") & " - " & rec("PartDescription") & " - " & rec("Qty") & " - " & rec("Price")
rec.MoveNext
Next intLoop
End If
MsgBox "Completed Export"
Set olApp = Nothing
Set olItem = Nothing
Exit_Command21_Click:
Exit Sub
ErrorHandler:
MsgBox Err.Description, , Err.Number
Resume Exit_Command21_Click
End Sub
I got it working. Here is the code in case anybody needs it.
Private Sub Command5_Click()
Dim olApp As Object
Dim olItem As Variant
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim strQry As String
Dim aHead(1 To 3) As String
Dim aRow(1 To 3) As String
Dim aBody() As String
Dim lCnt As Long
'Create the header row
aHead(1) = "Part#"
aHead(2) = "Description"
aHead(3) = "Qty"
lCnt = 1
ReDim aBody(1 To lCnt)
aBody(lCnt) = "<HTML><body><table border='2'><tr><th>" & Join(aHead, "</th><th>") & "</th></tr>"
'Create each body row
strQry = "SELECT tblePMParts.[Part#], tblePMParts.PartDescription, tblePMParts.Qty, tblePMParts.Price " & _
"FROM tblePMParts " & _
"WHERE (((tblePMParts.WOID)=" & [Forms]![fmremail]![Text1] & "));"
Set db = CurrentDb
Set rec = CurrentDb.OpenRecordset(strQry)
If Not (rec.BOF And rec.EOF) Then
Do While Not rec.EOF
lCnt = lCnt + 1
ReDim Preserve aBody(1 To lCnt)
aRow(1) = rec("[Part#]")
aRow(2) = rec("PartDescription")
aRow(3) = rec("Qty")
aBody(lCnt) = "<tr><td>" & Join(aRow, "</td><td>") & "</td></tr>"
rec.MoveNext
Loop
End If
aBody(lCnt) = aBody(lCnt) & "</table></body></html>"
'create the email
Set olApp = CreateObject("Outlook.application")
Set olItem = olApp.CreateItem(0)
olItem.Display
olItem.To = "Email"
olItem.Subject = "Test E-mail"
olItem.HTMLBody = Join(aBody, vbNewLine)
olItem.Display
End Sub
Somewhere in your code, put a line that says
X = [Forms]![fmremail]![Text1]
Put a breakpoint in your code (hopefully you know how to do that?) on that line. When the code breaks, press F8 to step to the next line, and then type ?X in the Immediate Window. Or you can just hover your mouse over the line with the break point. The point is, you need to see what your code thinks [Forms]![fmremail]![Text1] is equal to. If it's null, you have a problem with your reference. In that case, you may need to add ".Value" or ".Text" to the end of it.
Another thing to check is your datatype for WOID. if it's text, you need to surround it with single quotes.
strQry = "SELECT tblePMParts.[Part#], tblePMParts.PartDescription, tblePMParts.Qty, tblePMParts.Price " & _
"FROM tblePMParts " & _
"WHERE (((tblePMParts.WOID)='" & [Forms]![fmremail]![Text1] & "'));"

Convert Mail merge fields to fillable form fields in Word

I have a word template ready with mail merge fields.
Is there a easy way to convert them into fillable form fields?
In the end I want to create a fillable pdf form.
If it's a simple legacy field:
Public Sub ReplaceMergeFields()
On Error GoTo MyErrorHandler
Dim sourceDocument As Document
Set sourceDocument = ActiveDocument
Dim myMergeField As Field
Dim i As Long
For i = sourceDocument.Fields.Count To 1 Step -1
Set myMergeField = sourceDocument.Fields(i)
myMergeField.Select
If myMergeField.Type = wdFieldMergeField Then
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
End If
DoEvents
Next
Exit Sub
MyErrorHandler:
MsgBox "ReplaceMergeFields" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf & "Description: " & Err.Description
End Sub

When exporting Word review comments, how do you reference the sentence related to a comment?

I am trying to export a Word document's review comments. I want to export the sentence selection that was commented on followed by the comment.
Screen shot of the image: http://jspeaks.com/mswordcomment.png
I have found code to loop through the document comments, but I cannot figure out how to reference the sentence selection that the comment was related to.
The current logic is:
Sub ExportComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & cmt.Initial & cmt.Index & "," & cmt.Range.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s
End Sub
I tinkered with Selection.Range, however I cannot determine the proper object or property that contains the referenced sentence.
I would like to produce output like the following (if we use the example in picture above):
Sentence: Here are more sentences that contain interesting facts - Comment: This is an interesting fact.
Sentence: Here are more sentences that contain interesting facts. Here are more sentences that contain interesting facts. - Comment: This is a very interesting fact
I found someone on another site to solve this question.
The key to the solution is: cmt.Scope.FormattedText
Here is the function revised:
Sub ExportComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "Text: " & cmt.Scope.FormattedText & " -> "
s = s & "Comments: " & cmt.Initial & cmt.Index & ":" & cmt.Range.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s
End Sub
I have gathered several pieces of code and came to this solution:
Sub CopyCommentsToExcel()
'Create in Word vba
'TODO: set a reference to the Excel object library (Tools --> Reference --> Microsoft Excel 12.0 Object library)
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As Integer
Dim HeadingRow As Integer
HeadingRow = 3
Dim cmtRef As Range
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add ' create a new workbook
With xlWB.Worksheets(1)
' Create report info
.Cells(1, 1).Formula = "Reviewed document:"
' Create Heading
.Cells(HeadingRow, 1).Formula = "Index"
.Cells(HeadingRow, 2).Formula = "Page"
.Cells(HeadingRow, 3).Formula = "Line"
.Cells(HeadingRow, 4).Formula = "Comment"
.Cells(HeadingRow, 5).Formula = "Reviewer"
.Cells(HeadingRow, 6).Formula = "Date"
For i = 1 To ActiveDocument.Comments.Count
.Cells(2, 1).Formula = ActiveDocument.Comments(i).Parent
.Cells(i + HeadingRow, 1).Formula = ActiveDocument.Comments(i).Index
.Cells(i + HeadingRow, 2).Formula = ActiveDocument.Comments(i).Reference.Information(wdActiveEndAdjustedPageNumber)
.Cells(i + HeadingRow, 3).Formula = ActiveDocument.Comments(i).Reference.Information(wdFirstCharacterLineNumber)
.Cells(i + HeadingRow, 4).Formula = ActiveDocument.Comments(i).Range
.Cells(i + HeadingRow, 5).Formula = ActiveDocument.Comments(i).Initial
.Cells(i + HeadingRow, 6).Formula = Format(ActiveDocument.Comments(i).Date, "dd/MM/yyyy")
' .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Parent
' .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Application
' .Cells(i + 1, 7).Formula = ActiveDocument.Comments(i).Author
Next i
End With
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
Most valuable help from Microsoft Answers