OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
This is quite disappointing and frustrating...I am trying to make an investment portfolio workbook for a friend that retrieves stock/etf prices using Excel's built-in functionality. SOMETIMES when putting the link-to-price for a symbol into a cell there is an error generated, whether it is done manually or in code. Sometimes it works as expected.
Whether adding the link manually or in code the error message is "Something went wrong on our side and we couldn't link all your data. We're working to fix it"
When done in VBA, code is supposed to trap the error when it does happen and give user instructions to "Try Again". It worked well. But now it always generates a 1004 error.
But all of a sudden the error trapping does not work. It is ignored and the Excel debugger dialog appears and the offending line of code is highlighted. Needless to say, I do not want the user -- and Excel lightweight -- to learn about macro errors to use the workbook!
Is there something I'm missing? A reference? A different way to code the link-to-price insertion into a cell? More robust error trapping?
Whether adding the link manually or in code the error message is "Something went wrong on our side and we couldn't link all your data. We're working to fix it"
When done in VBA, code is supposed to trap the error when it does happen and give user instructions to "Try Again". It worked well. But now it always generates a 1004 error.
But all of a sudden the error trapping does not work. It is ignored and the Excel debugger dialog appears and the offending line of code is highlighted. Needless to say, I do not want the user -- and Excel lightweight -- to learn about macro errors to use the workbook!
Is there something I'm missing? A reference? A different way to code the link-to-price insertion into a cell? More robust error trapping?
Excel Formula:
sStepID = "Setting link-to-price for " & rCell.Value
sErrMsg = "Sometimes setting the link-to-price for" & Chr(10) _
& "a symbol does not work so TRY AGAIN!"
On Error GoTo ErrHandler
' Error occurs here.
' Try to put the link--to-price for the Symbol into its corresponding link cell.
rCell.Offset(0, 1).ConvertToLinkedDataType ServiceID:=268435456, LanguageCulture:="en-US"
End If
Next rCell
End With
Exit Sub
ErrHandler:
Call ErrorMessage(Err.Number, Err.Description, sSubName, sStepID, sErrMsg)
End Sub
'
' ----------------------------------------------------------------
' Procedure Name: ErrorMessage
' Purpose: Use to render the error messages from error handler.
' Procedure Kind: Function
' Procedure Access: Public
' Parameter piErrNum (Long): The Excel error number from the error handler.
' Parameter psErrDescr (): The Excel error description from the error handler.
' Parameter psSubName (): Name of calling sub or function.
' Parameter psStepID (): Name of the step within caller where the error occurred.
' Parameter psErrMsg (): Message to user about the error.
' Author: Jim
' Date: 7/24/2020
' ----------------------------------------------------------------
Function ErrorMessage( _
piErrNum As Long, _
psErrDescr As String, _
Optional psSubName As String = "", _
Optional psStepID As String = "", _
Optional psErrMsg As String = "")
' User interrupted operation
' If piErrNum = 18 Then Exit Function
On Error GoTo 0
Dim sMsg As String
Dim sTitle As String
sTitle = "Error Message"
sMsg = "Error #" & piErrNum & " occurred"
If psSubName <> "" _
Then sMsg = sMsg & " in procedure " & psSubName
sMsg = sMsg & "."
sMsg = sMsg & Chr(10) & Chr(10) & "Error Type: " & psErrDescr
If Right(psErrDescr, 1) <> "." And Right(psErrDescr, 1) <> "!" _
Then sMsg = sMsg & "."
If psStepID <> "" _
Then
sMsg = sMsg & Chr(10) & Chr(10) & "Step ID: " & psStepID
If Right(psStepID, 1) <> "." _
Then sMsg = sMsg & "."
End If
If psErrMsg <> "" _
Then
sMsg = sMsg & Chr(10) & Chr(10) & psErrMsg
If Right(psErrMsg, 1) <> "." And Right(psErrMsg, 1) <> "!" _
Then sMsg = sMsg & "."
End If
MsgBox sMsg, vbOKOnly + vbCritical, sTitle
Err.Clear
Application.StatusBar = False
End Function
'