Public Sub getXLcomments()
Dim xlx As Object, xlwb As Object, xlsht As Object
Dim rngJ As Range, rngO As Range
Dim x As Long, Lrow As Long
Dim strFilePath As String, strCmnts As String
'******this code not tested on wb that is already open*******
On Error GoTo errHandler
'open an Excel application...
Set xlx = CreateObject("Excel.Application")
xlx.ScreenUpdating = False
xlx.DisplayAlerts = False
xlx.Visible = False
'enable next line for your tests
''strFilePath = "\\Dave\Uli\BBSpreadsheet2024-2.xlsm"
strFilePath = "\\Dave\Uli\BBSpreadsheet2024-2.xlsm"
Set xlwb = xlx.Workbooks.Open(strFilePath)
'*****if needed, put this function in a standard module*****
'' Sub pause(sngSecs As Single)
'' Dim endTime As Long
''
'' endTime = Timer
'' Do Until Timer > endTime + sngSecs
'' Loop
''
'' End Sub
'***** end of pause function *****
'test without this call first?
''pause (2) 'allow time for server to open workbook before reading/writing
'if code is in a standard module, put sheet name next.
'Otherwise, maybe use "ActiveSheet" and run this via command buttons.
Set xlsht = xlwb.Worksheets("1990+")
'choose appropriate column to determine which is last row with data or use .Find method
Lrow = xlsht.Range("A" & xlsht.Rows.Count).End(xlUp).Row
With xlsht
'start at first row after header. In this case assume row 2
For x = 2 To Lrow
Set rngJ = .Range("J" & x)
Set rngO = .Range("O" & x)
If Not rngJ.Comment Is Nothing Then strCmnts = strCmnts & rngJ.Comment.Text & vbCrLf
If Not rngO.Comment Is Nothing Then strCmnts = strCmnts & rngO.Comment.Text & vbCrLf
Next
On Error GoTo errHandler
End With
Debug.Print strCmnts
exitHere:
xlx.ScreenUpdating = True
xlx.DisplayAlerts = True
'next line of code will make opened wb visible.
'If not wanted, code to close wb with or without saving
xlx.Visible = True
'or close wb without saving. THIS PART NW YET
''xlwb.Saved = True
''xlwb.Close
''xlx.Quit
''Set xlx = Nothing
Exit Sub
errHandler:
If Err.Number = 424 Or Err.Number = 462 Then Exit Sub 'wb or Excel was closed so is no longer available
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume exitHere
End Sub