Solved

Openoffice.org 3.0 macro

Posted on 2009-04-07
1
1,803 Views
Last Modified: 2013-12-27
Need to write a macro in OpenOffice.org version 3 that selects all of column A, copies all data in column A and then pastes over data in column A with TEXT.

My column A contains an equation, and when I am done with the calculations, I need a macro that will overwrite the equations with their current value.  I tried the record macro and ended up with the following code.  

When I originally did the Paste Special (while recording the macro), it worked and I ended up with only values in Column A.  But when I run the macro, it pastes the formulas, not the text into Column A.  Any help is appreciated.
sub resolved3

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 = "$A$2"
 

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
 

rem ----------------------------------------------------------------------

dim args2(0) as new com.sun.star.beans.PropertyValue

args2(0).Name = "ToPoint"

args2(0).Value = "$A$1"
 

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
 

rem ----------------------------------------------------------------------

dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
 

rem ----------------------------------------------------------------------

dim args4(5) as new com.sun.star.beans.PropertyValue

args4(0).Name = "Flags"

args4(0).Value = "S"

args4(1).Name = "FormulaCommand"

args4(1).Value = 0

args4(2).Name = "SkipEmptyCells"

args4(2).Value = false

args4(3).Name = "Transpose"

args4(3).Value = false

args4(4).Name = "AsLink"

args4(4).Value = false

args4(5).Name = "MoveMode"

args4(5).Value = 4
 

dispatcher.executeDispatch(document, ".uno:InsertContents", "", 0, args4())
 

rem ----------------------------------------------------------------------

dim args5(0) as new com.sun.star.beans.PropertyValue

args5(0).Name = "ToPoint"

args5(0).Value = "$A$8"
 

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args5())
 
 

end sub

Open in new window

0
Comment
Question by:fastfind1
1 Comment
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 500 total points
ID: 24092882
We could try and make the recorded macro work, but the code below should do the trick and is shorter.  Let me know how it works.  Just Paste it over top your current code.

-Bear

Sub PasteValues

	Dim oSheet

	Dim oRange

	Dim intCol

	Dim i
 

	' Get Access to Active Sheet

	oSheet = ThisComponent.CurrentController.getActiveSheet

	' Get the Current Range

	oRange = ThisComponent.getCurrentSelection
 

	' Find the Column Selected

	intCol = oRange.RangeAddress.StartColumn
 

	' Loop Through All Rows and Paste Value

	For i = oRange.RangeAddress.StartRow to oRange.RangeAddress.EndRow

		oOldCell = oSheet.getCellByPosition(intCol, i)

		oNewCell = oSheet.getCellByPosition(intCol, i)

		

		' If Numeric paste value, else paste string

		IF isnumeric(oNewCell.String) Then

			oOldCell.Value = oNewCell.Value

		Else

			oOldCell.String = oNewCell.String

		End If

	Next

	

End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Open office calc - Extract url from hyperlink. 7 4,264
Changing vsd files 4 1,418
Can't open Microsoft Word documents via OpenOffice 3.3 8 489
OpenOffice: starts automatically 5 507
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now