Hi there,
I have an operation I perform in spreadsheets that are generated for me. Basically what I do is I copy a template of sorts beside the tables, highlight the template of cells I copied in, find and replace some hardcoded variables in formulas with the cell numbers that the table takes up and then drag down specific columns to fill the cells. In the example I will post it will be 6 and 17, the table I am working with has 12 rows in total.
This is the macro recorder’s interpretation of what I do. I understand the macro recorder is inefficient and bloated but it’s the only way I can properly give an idea of what is going on.
REM ***** BASIC *****
sub UK12
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$F$6:$AC$9"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())'
rem ----------------------------------------------------------------------
dim args2(20) as new com.sun.star.beans.PropertyValue
args2(0).Name = "SearchItem.StyleFamily"
args2(0).Value = 2
args2(1).Name = "SearchItem.CellType"
args2(1).Value = 0
args2(2).Name = "SearchItem.RowDirection"
args2(2).Value = true
args2(3).Name = "SearchItem.AllTables"
args2(3).Value = false
args2(4).Name = "SearchItem.SearchFiltered"
args2(4).Value = false
args2(5).Name = "SearchItem.Backward"
args2(5).Value = false
args2(6).Name = "SearchItem.Pattern"
args2(6).Value = false
args2(7).Name = "SearchItem.Content"
args2(7).Value = false
args2(8).Name = "SearchItem.AsianOptions"
args2(8).Value = false
args2(9).Name = "SearchItem.AlgorithmType"
args2(9).Value = 1
args2(10).Name = "SearchItem.SearchFlags"
args2(10).Value = 71680
args2(11).Name = "SearchItem.SearchString"
args2(11).Value = "888"
args2(12).Name = "SearchItem.ReplaceString"
args2(12).Value = "6"
args2(13).Name = "SearchItem.Locale"
args2(13).Value = 255
args2(14).Name = "SearchItem.ChangedChars"
args2(14).Value = 2
args2(15).Name = "SearchItem.DeletedChars"
args2(15).Value = 2
args2(16).Name = "SearchItem.InsertedChars"
args2(16).Value = 2
args2(17).Name = "SearchItem.TransliterateFlags"
args2(17).Value = 1073743104
args2(18).Name = "SearchItem.Command"
args2(18).Value = 3
args2(19).Name = "SearchItem.SearchFormatted"
args2(19).Value = false
args2(20).Name = "SearchItem.AlgorithmType2"
args2(20).Value = 2
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Visible"
args3(0).Value = false
dispatcher.executeDispatch(document, ".uno:SearchResultsDialog", "", 0, args3())
rem ----------------------------------------------------------------------
dim args4(20) as new com.sun.star.beans.PropertyValue
args4(0).Name = "SearchItem.StyleFamily"
args4(0).Value = 2
args4(1).Name = "SearchItem.CellType"
args4(1).Value = 0
args4(2).Name = "SearchItem.RowDirection"
args4(2).Value = true
args4(3).Name = "SearchItem.AllTables"
args4(3).Value = false
args4(4).Name = "SearchItem.SearchFiltered"
args4(4).Value = false
args4(5).Name = "SearchItem.Backward"
args4(5).Value = false
args4(6).Name = "SearchItem.Pattern"
args4(6).Value = false
args4(7).Name = "SearchItem.Content"
args4(7).Value = false
args4(8).Name = "SearchItem.AsianOptions"
args4(8).Value = false
args4(9).Name = "SearchItem.AlgorithmType"
args4(9).Value = 1
args4(10).Name = "SearchItem.SearchFlags"
args4(10).Value = 71680
args4(11).Name = "SearchItem.SearchString"
args4(11).Value = "999"
args4(12).Name = "SearchItem.ReplaceString"
args4(12).Value = "17"
args4(13).Name = "SearchItem.Locale"
args4(13).Value = 255
args4(14).Name = "SearchItem.ChangedChars"
args4(14).Value = 2
args4(15).Name = "SearchItem.DeletedChars"
args4(15).Value = 2
args4(16).Name = "SearchItem.InsertedChars"
args4(16).Value = 2
args4(17).Name = "SearchItem.TransliterateFlags"
args4(17).Value = 1073743104
args4(18).Name = "SearchItem.Command"
args4(18).Value = 3
args4(19).Name = "SearchItem.SearchFormatted"
args4(19).Value = false
args4(20).Name = "SearchItem.AlgorithmType2"
args4(20).Value = 2
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args4())
rem ----------------------------------------------------------------------
dim args5(0) as new com.sun.star.beans.PropertyValue
args5(0).Name = "Visible"
args5(0).Value = false
dispatcher.executeDispatch(document, ".uno:SearchResultsDialog", "", 0, args5())
rem ----------------------------------------------------------------------
dim args6(0) as new com.sun.star.beans.PropertyValue
args6(0).Name = "ToPoint"
args6(0).Value = "$F$6"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args6())
rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "ToPoint"
args7(0).Value = "$F$6:$H$6"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args7())
rem ----------------------------------------------------------------------
dim args8(0) as new com.sun.star.beans.PropertyValue
args8(0).Name = "EndCell"
args8(0).Value = "$H$17"
dispatcher.executeDispatch(document, ".uno:AutoFill", "", 0, args8())
rem ----------------------------------------------------------------------
dim args9(0) as new com.sun.star.beans.PropertyValue
args9(0).Name = "ToPoint"
args9(0).Value = "$F$6:$H$17"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args9())
rem ----------------------------------------------------------------------
dim args10(0) as new com.sun.star.beans.PropertyValue
args10(0).Name = "ToPoint"
args10(0).Value = "$O$6:$AC$6"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args10())
rem ----------------------------------------------------------------------
dim args11(0) as new com.sun.star.beans.PropertyValue
args11(0).Name = "EndCell"
args11(0).Value = "$AC$17"
dispatcher.executeDispatch(document, ".uno:AutoFill", "", 0, args11())
rem ----------------------------------------------------------------------
dim args12(0) as new com.sun.star.beans.PropertyValue
args12(0).Name = "ToPoint"
args12(0).Value = "$O$6:$AC$17"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args12())
end sub
Basically what I want to do is make it so the current cell selected acts as the start point, F6 was in the above example, and then the hardcoded variables are changed up with the current row number for the 888 and then the current row number + 11 for the 999 placeholders. I’m guessing these can be done with some string splitter once the cell address variables are set.
So say if the row number I start on is 213, the range will be 213 and 224. The start point will ALWAYS be in the F column.
I have played around with ThisComponent.getCellAddress type of commands to no success.
Any help would be appreciated, thank you.