I am having an issue running 3 macros in a button. When I select the “Assign Action” I can only select one of the macros and I do not know the syntax for the code to run all three.
This first code has what I was trying to run for all three macros in the button (but it doesn’t work). It is based on code that people on here helped me with in the past. Note that the first part originally read runThemBoth and not runThemAll. I assume there is supposed to be different syntax for this.
Sub runThemAll(pEvent)
PutDataIntoFirstEmptyRowOfTheTargetRange2 ()
GetNamedRange ()
GetFirstEmptyCellInAColumnOfRange ()
End Sub
This code has all three macros that I want to run combined in the button:
REM ***** BASIC *****
Option Explicit
Sub PutDataIntoFirstEmptyRowOfTheTargetRange2
Dim oDoc as object
Dim oSourceRange as object
Dim oSourceCell as object
Dim oTargetRange as object
Dim oTargetCell as object
Dim lColNr as long
Dim sFormula as string
oDoc = ThisComponent
oSourceRange = GetNamedRange("TalList", oDoc)
oSourceCell = oSourceRange.ReferredCells.getCellByPosition(0,0)
sFormula = oSourceCell.Formula
oTargetRange = GetNamedRange("TalOwn", oDoc)
lColNr = 0 'zero based numbering
oTargetCell = GetFirstEmptyCellInAColumnOfRange(oTargetRange, lColNr)
oTargetCell.Formula = sFormula
oSourceCell.Formula = ""
end Sub
'_____________________________________________________________________________________________
Function GetNamedRange(sRange_name as string, optional oCalc_File as object) as object
Dim oDoc, oRange as object
If IsMissing(oCalc_File) then
oDoc = ThisComponent
else
oDoc = oCalc_file
end if
If len(sRange_name) = 0 or sRange_name = "" then
GetNamedRange = NOTHING
Exit function
End if
if oDoc.namedranges.hasByName(sRange_name) then
oRange = oDoc.NamedRanges.getByName(sRange_name)
GetNamedRange= oRange
else
GetNamedRange = NOTHING
end if
end function
'_____________________________________________________________________________________________
Function GetFirstEmptyCellInAColumnOfRange(oTheRange as object, lColNr as long) as object
Dim oCells as object
Dim oCell as object
Dim lRowNr as long
Dim i as long
oCells = oTheRange.ReferredCells
lRowNr = oCells.Rows.Count
For i = 0 to lRowNr-1
oCell = oCells.getCellByPosition(lColNr,i)
If oCell.getType() = 0 Then
GetFirstEmptyCellInAColumnOfRange = oCell
Exit function
end if
next i
end function
Understand that I am not a coder and this is something for myself at home that I have been trying to get to run better but I just can’t get a handle on the macros.