Code: Select all
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim isect As Range
Set isect = Intersect(Target, Range("Date"))
If Not isect Is Nothing Then
Target = Now()
End If
End Sub
Andrew
Code: Select all
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim isect As Range
Set isect = Intersect(Target, Range("Date"))
If Not isect Is Nothing Then
Target = Now()
End If
End Sub
Code: Select all
Sub MyDateTime
oDoc = ThisComponent
oView = oDoc.getCurrentController()
oSheet= oView.getActiveSheet()
oSel = oDoc.getCurrentSelection()
oAddr = oSel.getRangeAddress()
nSCol = oAddr.StartColumn
nSRow = oAddr.StartRow
nECol = oAddr.EndColumn
nERow = oAddr.EndRow
'print nSCol, nECol, nSRow, nERow
if (nERow-nSRow)>65536 or (nECol-nSCol)>1024 then
Print "Error too much cells selected!"
Exit sub
end if
'Put datetime into the cellrange
for j = nSCol to nECol
for i=nSRow to nERow
oCell = oSheet.getCellByPosition(j,i)
oCell.Value = Now
DateTimeFormat
next 'i
next 'j
End Sub
sub DateTimeFormat
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 = "NumberFormatValue"
args1(0).Value = 51
dispatcher.executeDispatch(document, ".uno:NumberFormatValue", "", 0, args1())
end sub
Yes you can. The code in the attached document owes a lot to Turtle47, who posted something using a MouseClickHandler a while back.ajardine wrote:Can't I set up a Listener (I'm not completely sure what they are) to recognize a double click inside a cell range and run the code from that event?
Andrew
I missed this query somehow. StartXMouseClickHandler is set to run on File > Open. The mouseclick dates any cell in the range named DateRange (Sheet1.A1:A20 in the example). As written, it will only handle a single rectangular range, but it could be adapted for more complex situations.leeand00 wrote:How did you assign the StartXMouseClickHandler to the cell mouse click event?
(I know how to do stuff like this on forms but I have no idea how its done on documents like spreadsheets and writer documents.)
1. Based on Charlie Young's sample file, how can I replace DateRange(A2:D20) created manually with SheetA and Row 2 to 20 by code ?Charlie Young wrote:ajardine wrote: The handler (a form of listener, I suppose) starts on File > Open, and it can be stopped with "StopXMouseClickHandler".
The named range is called "DateRange," and is set up as Sheet1.A2:D20.
You might change it to see what happens.
Just create a library with name Library1, and then copy/move the code into it.2. From my attached file, how can I move all codes of Module1 in Standard Library to Module1 in Library1 Library of this Calc file ?
After moving, double click event does not work.Zizi64 wrote:Just create a library with name Library1, and then copy/move the code into it.
Is this the reason ?Note:
Only the library "Standard" will be loaded automatically (at opening the file) into the memory.
Maybe. Try it.Is this the reason ?Note:
Only the library "Standard" will be loaded automatically (at opening the file) into the memory.
Code: Select all
Sub LoadLibrary(LibraryName as string)
If (Not GlobalScope.BasicLibraries.isLibraryLoaded(LibraryName)) Then
GlobalScope.BasicLibraries.LoadLibrary(LibraryName)
End If
end sub
Sub LoadLibrary1
Sub LoadLibrary("Library1")
end sub