Skip to main content
Bounty Awarded with 100 reputation awarded by User1974
added 261 characters in body
Source Link
TinMan
  • 4.3k
  • 1
  • 13
  • 25

Addendum

I added a sample. It shows how I would setup the project and demonstrates a couple of different techniques for working with ListObjects.

Table Demo

Addendum

I added a sample. It shows how I would setup the project and demonstrates a couple of different techniques for working with ListObjects.

Table Demo

Was the line that inserts the response into the Message column accidentally omitted?
Source Link
Option Explicit
Public Const TblDataName = "tblData"
Public Const TblDataLoadColumn = "Load?"
Public Const TblDataMessageColumn = "Message"
Public Const TblDataNumURLColumn = "URL"
Public Const TblDataTimestampColumn = "Message Timestamp"

Public Sub LoadRecords()
    Rem Refreshes the Concatenated Variables column
    Application.CalculateFull
    Dim message As String, response As String
    Dim n As Long
    
    With DataSheet.GetTblData
        .ListColumns(TblDataMessageColumn).Range.Interior.colorIndex = 0
        For n = 1 To .ListRows.Count
            If UCase(.ListColumns(TblDataLoadColumn).DataBodyRange(n).Value) = "Y" Then
                response = getHTTP(.ListColumns(TblDataNumURLColumn).DataBodyRange(n).Value) 'Send an HTTP request to Maximo using the value in the URL column
                .ListColumns(TblDataMessage).DataBodyRange(n) = response

                Rem Put the current date into the Message Timestamp column. Note: This is the Excel date, not a date from Maximo.
                .ListColumns(TblDataTimestampColumn).DataBodyRange(n) = Now()
            
                With .ListColumns(TblDataMessageColumn).DataBodyRange(n)
                    message = Left(response, 7) 'Return a message (created, updated, or error) and store it in the Message column.
                    .Interior.colorIndex = Switch(message = "Created", 43, message = "Updated", 37, True, 3)
                End With
            
            End If
        Next
    End With
End Sub
Option Explicit
Public Const TblDataName = "tblData"
Public Const TblDataLoadColumn = "Load?"
Public Const TblDataMessageColumn = "Message"
Public Const TblDataNumURLColumn = "URL"
Public Const TblDataTimestampColumn = "Message Timestamp"

Public Sub LoadRecords()
    Rem Refreshes the Concatenated Variables column
    Application.CalculateFull
    Dim message As String, response As String
    Dim n As Long
    
    With DataSheet.GetTblData
        .ListColumns(TblDataMessageColumn).Range.Interior.colorIndex = 0
        For n = 1 To .ListRows.Count
            If UCase(.ListColumns(TblDataLoadColumn).DataBodyRange(n).Value) = "Y" Then
                response = getHTTP(.ListColumns(TblDataNumURLColumn).DataBodyRange(n).Value) 'Send an HTTP request to Maximo using the value in the URL column

            Rem Put the current date into the Message Timestamp column. Note: This is the Excel date, not a date from Maximo.
            .ListColumns(TblDataTimestampColumn).DataBodyRange(n) = Now()
            
                With .ListColumns(TblDataMessageColumn).DataBodyRange(n)
                    message = Left(response, 7) 'Return a message (created, updated, or error) and store it in the Message column.
                    .Interior.colorIndex = Switch(message = "Created", 43, message = "Updated", 37, True, 3)
                End With
            
            End If
        Next
    End With
End Sub
Option Explicit
Public Const TblDataName = "tblData"
Public Const TblDataLoadColumn = "Load?"
Public Const TblDataMessageColumn = "Message"
Public Const TblDataNumURLColumn = "URL"
Public Const TblDataTimestampColumn = "Message Timestamp"

Public Sub LoadRecords()
    Rem Refreshes the Concatenated Variables column
    Application.CalculateFull
    Dim message As String, response As String
    Dim n As Long
    
    With DataSheet.GetTblData
        .ListColumns(TblDataMessageColumn).Range.Interior.colorIndex = 0
        For n = 1 To .ListRows.Count
            If UCase(.ListColumns(TblDataLoadColumn).DataBodyRange(n).Value) = "Y" Then
                response = getHTTP(.ListColumns(TblDataNumURLColumn).DataBodyRange(n).Value) 'Send an HTTP request to Maximo using the value in the URL column
                .ListColumns(TblDataMessage).DataBodyRange(n) = response

                Rem Put the current date into the Message Timestamp column. Note: This is the Excel date, not a date from Maximo.
                .ListColumns(TblDataTimestampColumn).DataBodyRange(n) = Now()
            
                With .ListColumns(TblDataMessageColumn).DataBodyRange(n)
                    message = Left(response, 7) 'Return a message (created, updated, or error) and store it in the Message column.
                    .Interior.colorIndex = Switch(message = "Created", 43, message = "Updated", 37, True, 3)
                End With
            
            End If
        Next
    End With
End Sub
added 3 characters in body
Source Link
Ben A
  • 10.8k
  • 5
  • 40
  • 103

Functions names should be Pascal case. II alternate between PascalPascal and Camel casecamelCase but never all uppercase. Only ConstsOnly constants and Enums should be all upper case (although I have been converted to using Pascal case for them also).

Functions names should be Pascal case. I alternate between Pascal and Camel case but never all uppercase. Only Consts and Enums should be all upper case (although I have been converted to using Pascal case for them also).

Functions names should be Pascal case. I alternate between Pascal and camelCase but never all uppercase. Only constants and Enums should be all upper case (although I have been converted to using Pascal case for them also).

Source Link
TinMan
  • 4.3k
  • 1
  • 13
  • 25
Loading