macro guide
DESCRIPTION
Macro GuideTRANSCRIPT
![Page 1: Macro Guide](https://reader031.vdocuments.net/reader031/viewer/2022012304/55cf94f3550346f57ba586ce/html5/thumbnails/1.jpg)
Page 1 of 8
Custom Capital IQ Macros for the VBA Environment Macros to Refresh Excel Plug-in formulas
o Macro to Refresh Selection
o Macro to Refresh Worksheet
o Macro to Refresh Workbook
o Macro for Double Refresh
o Macro for CIQ SCREEN Refresh
Macro to Unlink Excel Plug-in formulas
![Page 2: Macro Guide](https://reader031.vdocuments.net/reader031/viewer/2022012304/55cf94f3550346f57ba586ce/html5/thumbnails/2.jpg)
Page 2 of 8
Macros to Refresh Excel Plug-in formulas These macros can be used to refresh Excel Plug-in formulas. They are as follows.
Refresh Selection This macro refreshes selected range of cells in a worksheet. Public Sub RefreshSelection()
Dim Refreshbutton As CommandBarButton Set Refreshbutton = Application.CommandBars.FindControl(Tag:="menurefreshdatacell") Refreshbutton.Execute
End Sub
Refresh Worksheet This macro is used to refresh a single worksheet in a workbook. Public Sub RefreshWorksheet()
Dim Refreshbutton As CommandBarButton Set Refreshbutton = Application.CommandBars.FindControl(Tag:="menurefreshdatasheet") Refreshbutton.Execute
End Sub
Refresh Workbook This macro is used to refresh entire workbook. Public Sub RefreshWorkbook()
Dim Refreshbutton As CommandBarButton Set Refreshbutton = Application.CommandBars.FindControl(Tag:="menurefreshdatabook") Refreshbutton.Execute
End Sub
Double Refresh This macro refreshes the entire workbook twice. Public Sub RefreshWorkbook()
Dim Refreshbutton As CommandBarButton Set Refreshbutton = Application.CommandBars.FindControl(Tag:="menurefreshdatabook") Refreshbutton.Execute Refreshbutton.Execute
End Sub
![Page 3: Macro Guide](https://reader031.vdocuments.net/reader031/viewer/2022012304/55cf94f3550346f57ba586ce/html5/thumbnails/3.jpg)
Page 3 of 8
CIQ SCREEN Refresh Public Sub RefreshCIQScreen() Dim Refreshbutton As CommandBarButton Set Refreshbutton = Application.CommandBars.FindControl(Tag:="rcscreenrefresh") Refreshbutton.Execute End Sub
This macro refreshes CIQ SCREEN formulas of an active sheet. It finds CIQSCREEN() formulas and refreshes them with an interval of 10 seconds (default) between one CIQ SCREEN refresh and another. Initially this macro refreshes the current worksheet. Option Explicit Dim AddressArray() As String Dim Counter As Integer Dim i As Integer, DummySec As Integer 'set time interval here in seconds between one CIQSCREEN refresh to another Const RefreshIntervalSec As Integer = 10 Sub CiqScreenRefreshMain() Application.StatusBar = "Capital IQ: Please wait..." Dim CheckAddress As String, LastRow As Long, ColumnNo As Long, RowNo As Long Dim CellsFound As Variant Set CellsFound = Cells.Find(What:="CIQSCREEN", LookIn:=xlFormulas, LookAt:=xlPart) If Not CellsFound Is Nothing Then CheckAddress = CellsFound.Address Counter = 0 Do ColumnNo = CellsFound.Column RowNo = CellsFound.Row LastRow = Cells(65536, ColumnNo).End(xlUp).Row If LastRow > RowNo Then Range(Cells(RowNo + 1, ColumnNo).Address & ":" & _ Cells(LastRow, ColumnNo).Address).ClearContents End If Counter = Counter + 1 ReDim Preserve AddressArray(1 To Counter) AddressArray(Counter) = Cells(RowNo, ColumnNo).Address Set CellsFound = Cells.FindNext(CellsFound) Loop While Not CellsFound Is Nothing And CellsFound.Address <> CheckAddress End If If Counter > 0 Then
![Page 4: Macro Guide](https://reader031.vdocuments.net/reader031/viewer/2022012304/55cf94f3550346f57ba586ce/html5/thumbnails/4.jpg)
Page 4 of 8
'refreshing the current sheet for logging into excel plug-in Range("A1").Select Application.CommandBars.FindControl(Tag:="menurefreshdatasheet").Execute DummySec = 1 i = 1 Call CIQScreenRefreshRoutine Else MsgBox "No CIQ SCREEN formulas found.", , "Capital IQ Excel Plug-in" Application.StatusBar = False End If End Sub Private Sub CIQScreenRefreshRoutine() If i > Counter Then Application.StatusBar = False End End If Range(AddressArray(i)).Select If Selection.HasFormula = True Then Application.CommandBars.FindControl(Tag:="rcscreenrefresh").Execute DummySec = RefreshIntervalSec Else DummySec = 1 End If i = i + 1 Application.OnTime Now + TimeValue("00:00:" & DummySec), "CIQScreenRefreshRoutine" End Sub
Macro to Unlink Excel Plug-in formulas This macro can be used to unlink all types of Excel Plug-in formulas. It gives a choice to the user to input criteria to unlink i.e., unlink a selected range of cells, a worksheet or an entire workbook. After successful unlinking the macro allows the user to save a copy of current workbook. Sub UnlinkCIQ()
Application.ScreenUpdating = False Application.Calculation = xlCalculationManual On Error GoTo Check_Error Dim CheckAddress As String, ColumnNo As Long, RowNo As Long, _ CIQTextFound As Long, SingleTime As String, MyString As String
![Page 5: Macro Guide](https://reader031.vdocuments.net/reader031/viewer/2022012304/55cf94f3550346f57ba586ce/html5/thumbnails/5.jpg)
Page 5 of 8
Dim SearchStringArr(1 To 27) As String, i As Integer, _ MyAddress As String, ws As Worksheet, cellsfound As Variant Dim Result As Integer, CurrSheetName As String SearchStringArr(1) = "CIQTRADINGDAYS(" SearchStringArr(2) = "CIQTRADINGRANGE(" SearchStringArr(3) = "CIQTRADINGRANGEA(" SearchStringArr(4) = "CIQTRADINGRANGEM(" SearchStringArr(5) = "CIQTRADINGRANGEMA(" SearchStringArr(6) = "CIQTRADINGRANGEQ(" SearchStringArr(7) = "CIQTRADINGRANGEQA(" SearchStringArr(8) = "CIQTRADINGRANGEW(" SearchStringArr(9) = "CIQTRADINGRANGEWA(" SearchStringArr(10) = "CIQTRADINGRANGEY(" SearchStringArr(11) = "CIQTRADINGRANGEYA(" SearchStringArr(12) = "CIQRANGE(" SearchStringArr(13) = "CIQRANGEA(" SearchStringArr(14) = "CIQHI(" SearchStringArr(15) = "CIQLO(" SearchStringArr(16) = "CIQAVG(" SearchStringArr(17) = "CIQPC(" SearchStringArr(18) = "CIQ(" SearchStringArr(19) = "CIQGETDATE(" SearchStringArr(20) = "CIQAVAIL(" SearchStringArr(21) = "CIQDATEADD(" SearchStringArr(22) = "CIQRAND(" SearchStringArr(23) = "CIQRT(" SearchStringArr(24) = "CIQSCREEN(" SearchStringArr(25) = "CIQSP(" SearchStringArr(26) = "CIQSPLIT(" SearchStringArr(27) = "IQNameEval(" Result = Application.InputBox("Choose from the following..." & Chr(10) & _ " 1 - Unlink Current Selection" & Chr(10) & _ " 2 - Unlink Current Worksheet" & Chr(10) & _ " 3 - Unlink Current Workbook" & Chr(10) & _ " 4 - Exit", Title:="Capital IQ Excel Plug-in Unlink", _ Type:="1") If Result = 4 Or Result = False Then Application.ScreenUpdating = True End End If If Result < 1 Or Result > 4 Then MsgBox Prompt:="Invalid Input!", _ Title:="Capital IQ Excel Plug-in Unlink" Application.ScreenUpdating = True End End If CurrSheetName = ActiveSheet.Name For Each ws In Worksheets
ws.Activate
![Page 6: Macro Guide](https://reader031.vdocuments.net/reader031/viewer/2022012304/55cf94f3550346f57ba586ce/html5/thumbnails/6.jpg)
Page 6 of 8
'Unlink Selection Or Unlink Worksheet If Result = 1 Or Result = 2 Then If ws.Name <> CurrSheetName Then GoTo SkipNext End If End If For i = 1 To 27 MyString = SearchStringArr(i) SingleTime = "Yes" MyAddress = "" If Result = 1 Then Set cellsfound = Selection.Find(What:=SearchStringArr(i), _ LookIn:=xlFormulas, LookAt:=xlPart) Else Set cellsfound = Cells.Find(What:=SearchStringArr(i), _ LookIn:=xlFormulas, LookAt:=xlPart) End If MyAddress = cellsfound.Address If Not cellsfound Is Nothing Then Do
ColumnNo = cellsfound.Column RowNo = cellsfound.Row Cells(RowNo, ColumnNo) = Cells(RowNo, ColumnNo).Value If WorksheetFunction.IsText(Cells(RowNo, ColumnNo)) Then CIQTextFound = WorksheetFunction.Search(SearchStringArr(i), _ Cells(RowNo, ColumnNo).Value) If CIQTextFound > 0 Then CIQTextFound = 0 If SingleTime = "Yes" Then CheckAddress = cellsfound.Address SingleTime = "No" End If End If End If If Result = 1 Then Set cellsfound = Selection.FindNext(cellsfound) Else Set cellsfound = Cells.FindNext(cellsfound) End If MyAddress = cellsfound.Address
Loop While Not cellsfound Is Nothing And _ cellsfound.Address <> CheckAddress End If Next i
![Page 7: Macro Guide](https://reader031.vdocuments.net/reader031/viewer/2022012304/55cf94f3550346f57ba586ce/html5/thumbnails/7.jpg)
Page 7 of 8
SkipNext: Next ws Sheets(CurrSheetName).Select Application.ScreenUpdating = True SaveAsFile End Check_Error: If Err.Number = 91 Or Err.Description = _ "Unable to get the Search property of the WorksheetFunction class" Then Err.Clear Resume Next Else MsgBox "An error has occurred causing this operation to halt. Error details are as follows: " & _ Chr(10) & "Error Code: " & Err.Number & Chr(10) & "Error Context: " & Err.Description & _ Chr(10) & Chr(10) & "Help is available at " & Err.HelpFile, vbExclamation, "Capital IQ" End If Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub Private Sub SaveAsFile() Dim test As Integer, NewBook As Workbook, fName As Variant On Error GoTo Error_Situation Set NewBook = ActiveWorkbook test = MsgBox("Unlinking Successfull." & Chr(10) _ & "Do you want to save this file under a different name now?", _ vbYesNo, "Capital IQ Excel Plug-in Unlink") If test = 7 Then End Else ' Do fName = Application.GetSaveAsFilename(fileFilter:= _ "Excel File (*.xls), *.xls") ' Loop Until fName <> False If fName = False Then End End If NewBook.SaveAs Filename:=fName End If End
![Page 8: Macro Guide](https://reader031.vdocuments.net/reader031/viewer/2022012304/55cf94f3550346f57ba586ce/html5/thumbnails/8.jpg)
Page 8 of 8
Error_Situation: MsgBox "An error has occurred causing this operation to halt. Error details are as follows: " & _ Chr(10) & "Error Code: " & Err.Number & Chr(10) _ & "Error Context: " & Err.Description & Chr(10) & Chr(10) _ & "Help is available at " & Err.HelpFile, vbExclamation, "Capital IQ"
End Sub