[Solved] VBA program cell value

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Refugio
Posts: 3
Joined: Thu Jun 29, 2023 3:35 pm

[Solved] VBA program cell value

Post by Refugio »

Greetings. This program computes Properties of Shapes
However, I do not get it to work with Open Office. :cry: :cry: :cry:
The Cells( 3 , "B").Value is not read with the Open Office Compiler. Ie "...function procedure not defined."
N = worksheetname.getCellByPosition(3,2).Value - gets a different error: Object Variable Not set.

thought:

ws = worksheetname.getCell
n = ws.getCellByPosition(3,2).value

anyone here help with this?

Pls. help identify solutions.

Code: Select all

Rem Attribute VBA_ModuleType=VBADocumentModule
Rem Sub Page1
Rem 
Rem 
	Sub CommandButton1_Click()
	Dim PTOS(1 To 100, 1 To 2) As Double
Rem initialization
     N=0
     AREA = 0
     XCEN = 0
     YCEN = 0
     IXX = 0
     IYY = 0
     DIFER = 0
     IXY = 0
     IXXC = 0
     IYYC = 0
     IXYC = 0

Rem		N = Cells(3, 2).Value
		N = worksheetname.getCellByPosition(3,2).Value
Rem		N = Range("B3").Value

Rem Matrix Formulation
     For I = 1 To N
         PTOS(I, 1) = Cells(5 + I, 2).Value
         PTOS(I, 2) = Cells(5 + I, 3).Value
     Next
     N = N + 1
     PTOS(N, 1) = PTOS(1, 1)
     PTOS(N, 2) = PTOS(1, 2)
Rem Properties
     For I = 1 To N - 1
         X1 = PTOS(I, 1): Y1 = PTOS(I, 2)
         X2 = PTOS(I + 1, 1): Y2 = PTOS(I + 1, 2)
         AREA = AREA + (Y2 - Y1) * (X2 + X1) / 2
         XCEN = XCEN + (Y2 - Y1) / 8 * ((X2 + X1) ^ 2 + (X2 - X1) ^ 2 / 3)
         YCEN = YCEN + (X2 - X1) / 8 * ((Y2 + Y1) ^ 2 + (Y2 - Y1) ^ 2 / 3)
         IXX = IXX + (X2 - X1) * (Y2 + Y1) / 24 * ((Y2 + Y1) ^ 2 + (Y2 - Y1) ^ 2)
         IYY = IYY + (Y2 - Y1) * (X2 + X1) / 24 * ((X2 + X1) ^ 2 + (X2 - X1) ^ 2)
         DIFER = X2 - X1
         If DIFER = 0 Then DIFER = 0.000001
         IXY = IXY + (1 / 8 * (Y2 - Y1) ^ 2 * (X2 + X1) * (X2 ^ 2 + X1 ^ 2) + 1 / 3 * (Y2 - Y1) * (X2 * Y1 - X1 * Y2) * (X2 ^ 2 + X2 * X1 + X1 ^ 2) + 1 / 4 * (X2 * Y1 - X1 * Y2) ^ 2 * (X2 + X1)) / DIFER
     Next
     AREA = -AREA
     Cells(6, 7).Value = AREA
     XCEN = -XCEN / AREA
     YCEN = YCEN / AREA
     IYY = -IYY
     IXXC = IXX - AREA * YCEN ^ 2
     IYYC = IYY - AREA * XCEN ^ 2
     IXYC = IXY - AREA * XCEN * YCEN
     RESTA = IXXC - IYYC
     If RESTA = 0 Then RESTA = 0.000001
     TETA = 0.5 * Atn(-2 * IXYC / RESTA)
     Pi = 4 * Atn(1)
     TETA = TETA * 180 / Pi
     R = (IXXC / AREA) ^ (1 / 2)
Rem Print Results to cells
     Cells(8, 7).Value = IXX
     Cells(10, 7).Value = IYY
     Cells(12, 7).Value = IXY
     Cells(14, 7).Value = XCEN
     Cells(16, 7).Value = YCEN
     Cells(18, 7).Value = IXXC
     Cells(20, 7).Value = IYYC
     Cells(22, 7).Value = IXYC
     Cells(24, 7).Value = TETA
     Cells(26, 7).Value = R
End Sub
Rem 
Rem End Sub
Last edited by MrProgrammer on Mon Jul 10, 2023 7:11 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
Open Office 4.1.14 on Windows 10 Home 19045.3086
User avatar
Zizi64
Volunteer
Posts: 11365
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: VBA program Cell Value new?

Post by Zizi64 »

Use the API functions and procedures to control the OpenOffice. The Open/LibreOffice are not compatible with the MS VBA. (some VBA commands can run in Compatible mode, but not all of them.)

You can rewrite your macros in the StarBasic or in any another supported programming languages.
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.
JeJe
Volunteer
Posts: 2789
Joined: Wed Mar 09, 2016 2:40 pm

Re: VBA program Cell Value new?

Post by JeJe »

Put this at the top of the module for greater compatability with VBA - your "Cells" call will then work.

Code: Select all

Option VBASupport 1
See here:
viewtopic.php?t=56522

To get the sheet you can use a call like this:

Code: Select all

 worksheetname = thiscomponent.sheets.getbyname("Sheet1")
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Refugio
Posts: 3
Joined: Thu Jun 29, 2023 3:35 pm

Re: VBA program Cell Value new?

Post by Refugio »

JeJe wrote: Thu Jun 29, 2023 9:36 pm Put this at the top of the module for greater compatability with VBA - your "Cells" call will then work.

Code: Select all

Option VBASupport 1
:D :mrgreen: Great Thank You ! :fist:
Indeed the program works !
Open Office 4.1.14 on Windows 10 Home 19045.3086
User avatar
Zizi64
Volunteer
Posts: 11365
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: VBA program Cell Value new?

Post by Zizi64 »

Option VBASupport 1
It is better to rewrite your VBA macros, and to use the API functions, because the "Option VBASupport 1" can not give you 100% compatibility with the MS VBA.

Code: Select all

oDoc = ThisComponent
oSheet = oDoc.getcurrentcontroller.activesheet
N = oSheet.getCellByPosition(3,2).Value
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.
Refugio
Posts: 3
Joined: Thu Jun 29, 2023 3:35 pm

Re: VBA program Cell Value new?

Post by Refugio »

Zizi64 wrote: Fri Jun 30, 2023 6:39 am
Option VBASupport 1
It is better to rewrite your VBA macros, and to use the API functions, because the "Option VBASupport 1" can not give you 100% compatibility with the MS VBA.
Thnks for the knowledge over API’s. I write vba macros to tie together some information, “stitch welding”; OpenOffice allows me to be mindful of my ps and qs.

Otherwise: :crazy: is the result. ie. “Climb a ladder in the Winchester”. :ucrazy: “A break in the turning wheel brings tru rest”
Open Office 4.1.14 on Windows 10 Home 19045.3086
Post Reply