[Solved] SELECT command -macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
maciu1
Posts: 3
Joined: Tue Nov 15, 2016 2:22 pm

[Solved] SELECT command -macro

Post by maciu1 »

Hello,
I'm trying to run a VBA code into ods.file. The macro is very simple: as soon as a cell from column D is filled, automatically actually hour and date is recorder on the next 2 columns (on the same row). after that, the cursor must jump to the next row, first column.
The code runs fine in EXCEL, and only with an error on OpenOffice file: when the cursor jumped to the next row, first column, the cell is selected and coloured in blue. After that, the cell can't be used, until the arrow button from the keyboard is pressed.
I'm using a barcode scanner to collect data and with cell stuck the recording is stopped.
So, please, can someone to modify the code in order to be used? (I'm very beginner in macro stuff and code is made from multiple sources from net)

Thanks!

Rem Attribute VBA_ModuleType=VBADocumentModule
Option VBASupport 1
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("D2:D3000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim lc As Long
With Application
.EnableEvents = False
.ScreenUpdating = False
lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
If lc = 1 Then
Cells(Target.Row, lc + 1) = Format(Now, "hh:mm")
Cells(Target.Row, lc + 2) = Format(Now, "dd/mm/yyyy")
ElseIf lc > 2 Then
Cells(Target.Row, lc + 1) = Format(Now, "hh:mm")
Cells(Target.Row, lc + 2) = Format(Now, "dd/mm/yyyy")
End If
.EnableEvents = True
.ScreenUpdating = True
End With
ActiveCell.Offset(1, -3).Select
End Sub
codebar scanner.JPG
codebar scanner-excel.JPG
Last edited by maciu1 on Wed Nov 16, 2016 12:04 pm, edited 1 time in total.
OpenOffice 4.1.3 on Windows XP
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: SELECT command -macro

Post by Zizi64 »

I'm trying to run a VBA code into ods.file.
The StarBasic and the API of the AOO / LO is not compatible with the MS VBA codes. (API: Application Programming Interface)

The LibreOffice has a littlebit higher compatibility with the VBA codes (relative to the AOO) but it has not but 100% compatibility.
You need REWRITE all of MS VBA macros by using the AOO/LO API functions.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
maciu1
Posts: 3
Joined: Tue Nov 15, 2016 2:22 pm

Re: SELECT command -macro

Post by maciu1 »

I know there is no 100% compatibility VBA~AOO/LO macros, but in my case just 1 command needs adjustments...the rest of the code running fine on AOO.
OpenOffice 4.1.3 on Windows XP
User avatar
einstein
Posts: 47
Joined: Sat Nov 05, 2016 1:45 am
Location: State of Mexico, México.

Re: SELECT command -macro

Post by einstein »

I guess your excel macro works on LO.
To work on LO try changing:

Code: Select all

ActiveCell.Offset(1, -3).Select
by

Code: Select all

document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "By"
args1(0).Value = 3
args1(1).Name = "Sel"
args1(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args1())
args1(0).Value = 1
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args1())
lo 5.1.6.2 | aoo 4.1.3 | win 7/10
All I know is that I know nothing
maciu1
Posts: 3
Joined: Tue Nov 15, 2016 2:22 pm

Re: SELECT command -macro

Post by maciu1 »

@einstein, you are the man! the code is running fine with your extra lines.
THANKS!
OpenOffice 4.1.3 on Windows XP
Post Reply